English 中文(简体)
j 质量选择权[名称=价值]
原标题:jQuery Selector [name=value] doesn t work

I m a newbie to jQuery. I met a issue when using the [name=value] selector. Here is the HTML:

<input type="number"/>

Very simple, right? And here is the JS:

$("input").val(100);
$("input[value= 100 ]").val(200)​

The result is: the first line of the script works, but not the second line.(Chrome, FF, IE9) The both line works in IE8. How this happens? BTW, I m using jQuery1.7.2. Or you can just test the above code on http://jsfiddle.net/wzKNV/

问题回答

attribute-qualitys Selectedoreck the attribute, but the .val(> only change the property, so the selectedor don t see the Update.

当地人<代码>querySelectorAll ,该方法使Query/Sizzle的违约情况得以实施这一“仅限”行为。

如果您打破了<代码>的选任人,那么就必须使用Siezzle,它将发挥作用......

// v------made it a non-standard Sizzle selector
$(":input[value= 100 ]").val(200);

这是因为Siezzle 选择器必须符合qSA 选择。 当然,这改变了挑选人的含义,但有助于说明。


为保持使用标准甄选人(这是海事组织的良好想法),可使用<代码>filter(<>.

$("input").filter(function() { return this.value ===  100 ; })
          .val(200);

如果有

<input type="nubmer" disabled="disabled" value="100" />​ // your fiddle have no `value`

then

$("input[value= 100 ]").val(200)​​​​​​​

工作





相关问题
Image rendered with wrong colors in IE8

I have a gradient image as a PNG (no transparency) in a web-page. By taking a screenshot of Chrome showing the page and cropping the image from the page, I see the exact same colors are drawn as the ...

Determine Mobile Internet Explorer version

I need to determine the version of Mobile Internet Explorer on a Windows Mobile 6.1 device. So that I can report the same user-agent string as is being used by Mobile Internet Explorer. The user-...

CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

Internet Explorer only part loading JavaScript/CSS

I m having trouble with my local development environment where IE (6 through to 8) is only part loading JavaScript/CSS files. It throws random errors at random places in jquery.min.js every time I ...

IE doesn t run Javascript when you click back button

I ve built a shop with tons of JS running. One of the pieces of the cart, is a zip code field which is required to calculate shipping cost. This works fine going through the cart. Now clicking ...

热门标签