关于如何用JQuery判断当前操作的表单类型
今天碰到了这样的问题,以为Jquery和原生态的javascript一样可以用type属性去判断,结果是false。
例如:
<select id="item1"><option value="1">1</option></select>和<input type="text" id="item2">
用document.getElementById("item1").type可以得到值"select-one",而用$("#item1").type是不行的。
所以只能换个思想去做这件事,用jquery的is();
if($("#item1").is('select')){
alert('is select');
}
if($("#item2").is('input')){
alert('is input');
}
挨个判断虽然麻烦了点,但好在表单项的数量也就几个,总算能达到设计上的目的