javascript jQuery:如何找到具有特定 id 的 li 标签
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26761235/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
jQuery: How to find a li-tag with a specific id
提问by Zwen2012
I have a <ul>
with many <li>
.
My <li>
's have different id's: for example: <li class="image" id=1>....</li>
How can I find now this <li>
with the id=1 ??
I tried this-->
我有<ul>
很多<li>
。我<li>
的有不同的 id:例如:<li class="image" id=1>....</li>
我现在如何<li>
用 id=1找到这个?我试过这个-->
var deleteImage = $("ul").find( ".image" ).attr("id").val(1);
...but it doesnt work. Any idea? THANKS!!!
...但它不起作用。任何的想法?谢谢!!!
回答by Antoine Combes
This is a basic JQuery/CSS selector:
这是一个基本的 JQuery/CSS 选择器:
var deleteImage = $("ul").find( "#1.image" );
回答by Thomas Bormans
ID's should neverstart with numbers. Change your id's to image1, image2, image3, ... Then use:
ID的应该永远以数字开头。将您的 id 更改为 image1, image2, image3, ... 然后使用:
$('#image1').functionToExecute();