jquery遍历
当我点击一个链接时,我在变量中获取它的href值(该数字代表一个唯一的id),然后...我有一个单独的ul:
<ul class="class_one">
<li class="class_two"><a href="2345">some text</a></li>
<li class="class_three"><a href="6789">some text</a></li>
</ul>
我想做的是看看我是否有任何“a”在我的“ul”中,它的 id 与我在变量中存储的 id 相同。
我尝试了这样的事情(当然没有结果):
$('ul.class_one').find('a[href="' + myVar + '"]')
//and if it finds no element do something
//i think is something wrong with the quotes ('a[href="' + myVar + '"]')
when i click on a link i take it's href value in a variable (the number represents an unique id), then...i have a separate ul:
<ul class="class_one">
<li class="class_two"><a href="2345">some text</a></li>
<li class="class_three"><a href="6789">some text</a></li>
</ul>
what i'm trying to do is to see if i have any "a" in my "ul" that has the same id that i stocked in my variable.
i tried something like this( of course with no result ):
$('ul.class_one').find('a[href="' + myVar + '"]')
//and if it finds no element do something
//i think is something wrong with the quotes ('a[href="' + myVar + '"]')
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您是否尝试过交换报价? jQuery 可能使用单引号进行属性选择匹配...
来自 jQuery 文档
Have you tried swapping your quotes? jQuery might be using single quotes for attribute selection matching...
From jQuery Documentation
可以完全删除引号...
应该可以
It's possible to remove the quotes altogether...
Should work
CSS 和 jQuery 都使用单引号。
CSS, and jQuery by extension, uses single quotes.