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 })更多推荐
发布评论