今天小菜處理下拉菜單級聯(lián)問題時,想獲取HTML標簽中某個事件的內(nèi)容,也就是值,比如從<select onchange="javascript:test();"></select>中獲取javascript:test();。
小菜想通過事件中的信息,確定下一級的菜單,但是這個貌似很簡單的問題,卻讓小菜糾結了一番。
稍微懂點JQuery的童鞋,可能會嘗試這樣獲取:
復制代碼 代碼如下:
$(document).ready(function(){
var onchangeValue = $("#city").attr("onchange");
alert(onchangeValue);
});
復制代碼 代碼如下:
$(document).ready(function(){
var onchangeValue = document.getElementById("city").getAttributeNode("onchange").nodeValue;
alert(onchangeValue);
});
新聞熱點
疑難解答
圖片精選