[英]How to find whether the class attribute is present or not in the input element using Jquery
我需要使用jquery查找在输入属性中指定的类名称
<Html>
<body>
<input type="text" class="name"/>
</body>
</Html>
这是我如何使用jQuery查找类名
$('input').hasClass('name') ? alert('has class name') : alert('has no class name')
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <input type="text" class="name"/>
说明:确定是否为任何匹配的元素分配了给定的类。
尝试这个:
var className = $('.name').attr('class'); alert(className);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <input type="text" class="name"/>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.