我需要找到单选按钮、文本和选择的输入类型。很容易找到任何东西的输入类型,<input type="x">
因为$(this).attr("type")
会返回x
我的问题是我需要支持<select>
没有 type 属性的元素。最终目标是返回单选、文本或选择。
我想过做这样的事情,但我很好奇是否有更好的方法:
if ($(this).tagName == "input") {
var result = $(this).attr("type"); //returns radio or text (the attr type)
} else {
var result = $(this).tagName; //returns select (the element type)
}
谢谢大家!