我试图通过.list里面的p标签内容搜索,我可能只是在复杂化,但我的警报不工作,也许是因为其他代码我在页面上没有发挥作用,但我想知道是否有人能帮我弄清楚我哪里出错了。jQuery搜索使用标签内的.find
JS
$(document).ready(function() {
var sresults = $('.mainsearch input').val();
var sfinder = $('.list p').find(sresults).text(sresults);
$('.mainsearch input').keyup(function() {
$('.search-help').append(sfinder);
alert(sfinder);
});
});
HTML
<div class="mainsearch">
<input/>
<div class="search-help">Results:
</div>
</div>
<div class="list">
<span><p>test</p></span>
<span><p>another result</p></span>
<span><p>yet another result</p></span>
</div>
什么是 “我的警报不工作” 是什么意思?你想要做什么,它在做什么?你的代码应该在每次你从你的'输入'字段的一个键上拿起一个手指时提醒一些事情(可能是一个空的对话框,因为'sfiner'没有被定义在任何地方)。 – Amadan
sresults不会包含任何东西,因为你的'input'标签没有任何属性,所以找不到任何东西 – SpaceBison
'sfinder'应该包含什么?你用来给这个变量赋值的代码没有意义。 – Blazemonger