如何從JQuery選擇器中獲取DOM元素我很難從jQuery選擇器獲得實際的DOMElement。樣本代碼:<input type="checkbox" id="bob" />
var checkbox = $("#bob").click(function() { //some code } )在另一段代碼中,我試圖確定復(fù)選框的選中值。 if ( checkbox.eq(0).SomeMethodToGetARealDomElement().checked )
//do something.拜托,我不想做: if ( checkbox.eq(0).is(":checked"))
//do something這讓我繞過了復(fù)選框,但其他時候我需要真正的DOMElement。
3 回答

米脂
TA貢獻1836條經(jīng)驗 獲得超3個贊
$("table").get(0);
$("table")[0];
$(":checkbox").click(function() { if ($(this).is(":checked")) { // do stuff }});
$(":checkbox").each(function(i, elem) { $(elem).data("index", i);});$(":checkbox").click(function() { if ($(this).is(":checked") && $(this).data("index") == 0) { // do stuff }});
XmlHttpRequest
.

富國滬深
TA貢獻1790條經(jīng)驗 獲得超9個贊
jQuery("#bob").get(0).outerHTML;
<input type="text" id="bob" value="hello world" />
- 3 回答
- 0 關(guān)注
- 401 瀏覽
添加回答
舉報
0/150
提交
取消