jQuery basic help -
I'm sure I'm going to lose some representative points for this, because this is a basic question but I
This element has been given in my document:
(which produces the following markup:
& quot; Input checked "" checked "id =" isAlwaysValidCheckBox "name = "IsAlwaysValid" onchange = "showHideValidSetList ()" type = "checkbox" value = "true" /> and
)
Then this function is using a jQuery selector:
& lt; script type = "text / javascript" & gt; function ShowHideValidSetList () (checked ($ ("#IsAlwaysValidCheckBox"). {Warning ("IsAlwaysValidCheckBox checked"); Return;} and {Warning ("IsAlwaysValidCheckBox check
The Javascript must be equal to one by using DOM:
& quot; Lt; script type = "text / javascript" & gt; function showHideValidSetList (if checked (document.getElementById ("IsAlwaysValidCheckBox")) {Warning ("IsAlwaysValidCheckBox checked"); return;} and {warnings} ("IsAlwaysValidCheckBox is not checked"); Return; }} & Lt; / Script & gt;
Right? But the Javascript version works as expected, while jQuery always takes the "second" branch, showing it is not actually seeing the status of the checkbox.
What am I doing?
Thanks for the effect with me.
Use this:
if ($ (checkbox control) Instead of:
($ ("#IsAlwaysValidCheckBox") though it looks like the jQuery selector DOM elements (Such as a checkbox), they actually return a jQuery object, in which
checked
. You can see it in the uncompressed jquery source code (from) most clearly:jQuery.fn = jQuery.prototype = {init: function (selector, context) {// ... / Handle / $ (DOMElement) if (selector.nodeType) {this [0] = selector; This.length = 1; This.context = selector; return it;} // ...}}
Many interesting jQuery methods (such as animate, atri, html, etc) work on
this.context
, whenever you apply, specify or redefine any selector
Comments
Post a Comment