jquery按属性值选择不工作

编程入门 行业动态 更新时间:2024-10-25 10:26:58
jquery按属性值选择不工作 - 在值空间中进行处理(Jquery select by attribute value not working - incase with space in value)

在我的复选框中,我使用选择使用值的元素..对于(样本)我做了这样的..

<form> <input type="checkbox" value="one 234" /> </form> function doit(){ var x = "one 234" $(':checkbox[value='+x+']') .css({border:"1px solid green"}) } doit();

但是不起作用..如果我删除中间的“一个234”的值 - 它的工作原理。 如何处理这种情况..?

这里是jsfiddle

In my checkboxes, i am using select the element using values.. for that (sample) i made like this..

<form> <input type="checkbox" value="one 234" /> </form> function doit(){ var x = "one 234" $(':checkbox[value='+x+']') .css({border:"1px solid green"}) } doit();

But is doesn't work.. in case if i remove the space inbetween the value of "one 234" - it works. how to handle this kind of situation..?

here is the jsfiddle

最满意答案

使用引号:

$(':checkbox[value="'+x+'"]')

或过滤器 ,我个人认为它更清洁,并且不必担心任何字符转义:

$(':checkbox').filter(function(){ return this.value===x })

Use quotes :

$(':checkbox[value="'+x+'"]')

Or filter, which I personally find cleaner and with which you don't have to worry about any character escaping :

$(':checkbox').filter(function(){ return this.value===x })

更多推荐

本文发布于:2023-08-03 09:43:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1384967.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:属性   工作   jquery

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!