[英]jQuery onClick for <li> element not a function
奇怪的是,下面的代碼拋出了一個 jQuery.Deferred 異常:
var miscUls = $("#miscellaneous").find("ul");
miscUls.children('li')[0].onClick(function() {
modal.style.display = "none";
});
...和...
miscUls.children().first().onClick(....
...和
miscUls.children('li').eq(0).onClick(....
不太確定如何風格化選擇器,我只是想將 onClick() 事件處理程序附加到該無序列表中的第一個元素。 also tried to assign a unique id to that element, and select it via也試過一個唯一的ID分配給該元素,並通過選擇它
miscUls.getElementById("newUser").onClick(....
無濟於事。 對這個看似簡單的問題的任何幫助將不勝感激。 謝謝。
在li
上嘗試:first-child
選擇器,就像這樣
$("#miscellaneous ul li:first-child").click(function(){
// your code
})
Jquery 的點擊事件助手是點擊而不是 onClick
var miscUls = $("#miscellaneous").find("ul");
miscUls.children('li')[0].click(function() {
modal.style.display = "none";
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.