我有这样的 HTML 代码:
<div class="a">html value 1</div>
<div class="a">html value 2</div>
我怎样才能访问html value 1
and html value 2
使用jquery?
分别地:
$('div.a:eq(0)').html(); // $('div.a:eq(0)').text();
$('div.a:eq(1)').html(); // $('div.a:eq(1)').text();
使用循环:
$('div.a').each(function() {
console.log( $(this).html() ); //or $(this).text();
});
Using .html()
$('div.a').html(function(i, oldHtml) {
console.log( oldHtml )
});
DEMO http://jsfiddle.net/2HpN7/
Using .text()
$('div.a').text(function(i, oldtext) {
console.log( oldtext )
});
DEMO http://jsfiddle.net/2HpN7/1/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)