在html代码里面如何加入jquery的变量

var txt=" <tr><td>Mark<button type='button' class='close' aria-hidden='true'>×</button></td> <td>1</td> </tr>";

var value=$('#label').val();
如何把value插进<td></td>里面呢

jQuery操作html时可以使用变量,html不能直接使用jQuery的变量

示例:

//在id为first的div里添加jQuery变量值内容
$(function(){
    var temp="这是内容";
    $("div#first").append(temp);
    
    //此时id为first的div内的html如下,jQuery变量的值添加进去了
    <div id="first">
        这是内容
    </div>
    
   
    //或者在div内插入<h1></h1>标签
    $("div#first").append("<h1>"+temp+"</h1>");
      
    //此时id为first的div内的html如下,html内有jquery变量的值
    <div id="first">
        <h1>这是内容</h1>
    </div>
});

温馨提示:答案为网友推荐,仅供参考
第1个回答  推荐于2017-09-30
<td id="td"></td>

jquery代码:
$("#td").text('插入值');即可

td要有ID

本回答被提问者采纳
第2个回答  2015-08-06
引入jquery文件就OK。
第3个回答  2013-12-05
你想插入到那个td,前面的还是后面的??

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网