美文网首页
jquery进行标签的属性操作

jquery进行标签的属性操作

作者: Oo晨晨oO | 来源:发表于2018-03-14 23:07 被阅读4次

1、html() 取出或设置html内容

// 取出html内容

var $htm = $('#div1').html();

// 设置html内容

$('#div1').html('<span>添加文字</span>');

2、prop() 取出或设置某个属性的值

// 取出图片的地址

var $src = $('#img1').prop('src');

// 设置图片的地址和alt属性

$('#img1').prop({src: "test.jpg", alt: "Test Image" });

相关文章

网友评论

      本文标题:jquery进行标签的属性操作

      本文链接:https://www.haomeiwen.com/subject/sftcqftx.html