$().attr()的使用方法 && $().html()与$().text()的差别

<1>$().attr()的使用方法

</pre><pre class="html" name="code"><html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script src="script/jquery-1.11.0.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(function () {
            //attr用来设置Jquery没有封装的对象属性
            //-----------------------------------------------------------------------------

            $("#btnSubmit").attr("disabled", "true"); //attr用来设置Jquery没有封装的对象属性,由于Jquery没有封装disabled属性,这就是通过attr来将获取到的对象的disabled属性设为true。


            //-----------------------------------------------------------------------------

            //将input的class属性名字设为"inputClass"
            $("input").attr("class", "inputClass"); 
            
            //-----------------------------------------------------------------------------

            //这里将img的两个属性一并设置了值。就能够用到json格式:{"属性1":值,"属性2":值}
            $("img").attr({ "src": "/images/123.jpg", "alt": "123456" });



            // $("img").attr({ "src": "/images/123.jpg", "alt": "美女图片" }); 也能够写成以下的形式
            $("img").attr("src", "/images/123.jpg").attr("alt", "美女图片");

            //-----------------------------------------------------------------------------

            //将a标签的href属性设为"http://www.baidu.com",将它的html()内容设为"百度"
            $("a").attr("href", "http://www.baidu.com").html("百度");
        })
       
    </script>
</head>
<body>
<input type="button"  value="提交" id="btnSubmit" />
<img/>
<a></a>
</body>
</html>


<2>$().thml()与$().text()的差别

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script src="http://localhost:41928/Jquery/jquery-1.10.2.js" type="text/javascript"></script>
    <script type="text/javascript">
        
        $(function () {
            //.thml()是在块中加html代码
            $("div").html("<a href='http://www.baidu.com'>百度</a>"); 
            alert($("div").text());  //输出是是一个百度的超链接
        })

        $(function () {
            //.text()是在块中的文字
            $("div").text("<a href='http://www.baidu.com'>百度</a>");
            alert($("div").text()); //输出的是 【<a href='http://www.baidu.com'>百度</a>】这么一段文字
        })

      
    </script>
</head>
<body>
<div></div>

</body>
</html>



http://blog.sina.com.cn/s/blog_561be372010008ev.html


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
const html =`<tbody> <tr> <td><input type="checkbox" v-model="RemitInBox" class="RemitInBox v-pristine v-valid" name="RemitInBox" value="0" v-checked="data.CheckFlag" v-disabled="data.FndDrc!='01' || data.BusiState!='10'" id="List0_RemitIn" v-click="clickBox($index,data)"></td> <td><span v-show="data.FndDrc!='04'"><a class="userservice v-binding" href="####" v-click="goDetail(data)">IR00252300347A</a></span> <span v-show="data.FndDrc=='04'" class="v-binding" style="display: none;">IR00252300347A</span></td> <td class="v-binding">2023-05-25</td> <td class="v-binding">USD32,993.50</td> <td class="v-binding">1/FLOKSER KIMYA SANAYI VE TICARET 1...</td> <td class="v-binding">31980005000107125</td> <td><span v-show="data.FndDrc=='01'">入账</span> <span v-show="data.FndDrc=='04'" style="display: none;">退汇</span> <span v-show="!(data.FndDrc=='04'||data.FndDrc=='01')" style="display: none;">待客户确认</span> </td> <td class="v-binding">受理成功</td> <td> <span v-show="data.FndDrc=='01' &amp;&amp; data.BusiState=='10'"> <a href="#" v-click="remitInPrint(data.BsnSrlNo)" class="userservice"> 打印 </a> </span> </td> </tr> </tbody>` const cheerio= require('cheerio') const $ = cheerio.load(html) console.log($) const result = []; $('tr').each((i, tr) => { const tds = $(tr).find('td'); const data = { RemitInBox: $(tds[0]).find('input').attr('v-checked') === 'true', IRNumber: $(tds[1]).find('a').text(), Date: $(tds[2]).text(), Amount: $(tds[3]).text(), Account: $(tds[4]).text(), AccountNumber: $(tds[5]).text(), Status: $(tds[6]).text(), Result: $(tds[7]).text(), Print: $(tds[8]).find('a').length > 0, }; result.push(data); }); console.log(result);
05-26
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值