我正在尝试获取具有 repeat
类的 div
元素。所以我尝试了这个,但它显示 undefined
。
var data = '<div class="test form-group col-xs-6 repeat" id="repeat_py">\n <div class="kv col-lg-2">index:\n<pre class="num">0</pre></div>\n<div><span class="kv">value: <pre class="num">m</pre></span></div></div>'
alert($(data).find('div.repeat').html())
最佳答案
你需要.filter()
而不是 .find()
Reduce the set of matched elements to those that match the selector or pass the function's test.
$(data).filter('div.repeat').html()
var data = '<div class="test form-group col-xs-6 repeat" id="repeat_py">\n <div class="kv col-lg-2">index:\n<pre class="num">0</pre></div>\n<div><span class="kv">value: <pre class="num">m</pre></span></div></div>'
alert($(data).filter('div.repeat').html())
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
关于javascript - 如何使用 jquery 获取特定元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34961149/