That’s right, when I was doing jQuery training recently, I encountered a problem when jQuery determines whether an element exists.
The question is as follows: Please add Id=rad4 after "Select Button 3". In the selected state, the HTML control with the text "Select Button 4" can only be added once (you can choose to use js native or JQuery to implement it)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
|
It is enough to determine whether the object exists. if (!document.getElementById("rad4")) but in jQuery if (!$("#rad4")) is always false. I thought it was the same as javascript but it is not the case
In jQuery. Once wrapped by the $("") wrapper, it is an object, not null or undefined, so!$("#rad4")
Always false. The correct approach is as follows
If there is no object in the wrapper, the length will be 0; that’s all you need
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|