大佬教程收集整理的这篇文章主要介绍了jQuery查找输入类型(也可以选择),大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我的问题是我需要支持< 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) }
感谢所有!
$.fn.getType = function(){ return this[0].tagName == "INPUT" ? this[0].type.toLowerCase() : this[0].tagName.toLowerCase(); }
并使用它这样
$(".element").getType(); // Will return radio,text,checkBox,SELEct,textarea,etc (also DIV,SPAN,all element types) $(".elList").getType(); // Gets the first element's type
哪个将获得所选择的第一个元素的类型。
其他信息
如果你只想要一些选择器,你可以使用这个:
$("input:text,input:radio,SELEct");
或选择所有表单控件(more info):
$(":input") // can return all form types
以上是大佬教程为你收集整理的jQuery查找输入类型(也可以选择)全部内容,希望文章能够帮你解决jQuery查找输入类型(也可以选择)所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。