我正在構建一個交互式表單並根據用戶的回答加載字段。現在我只有兩種物體「輸入收音機」和「textarea」。當我通過JQuery獲得答案的價值時,我怎麼能知道我在最後加載的字段集內處理了什麼對象?JQuery:如何知道我們正在處理的表單對象的類型?
這就是我想:
$.fn.getNodeName = function() { // returns the nodeName of the first matched element, or ""
return this[0] ? this[0].nodeName : "";
};
//var $something = $('input[type=radio]:checked:last');
var $something = $('fieldset:last').parent('nth-child(2)');
//$('#news ul li:first-child').addClass('active');
alert($something.getNodeName());
但它不工作... 感謝。
「':radio'」不是在CSS現有pseudoselector 。也許你打算爲該部分使用一個屬性選擇器,例如'輸入[類型=無線電]:檢查:last'? –
已更新的問題@Jordan – Roger