jQuery-查找输入按类的一部分具有多个类
我有如下HTML:jQuery-查找输入按类的一部分具有多个类,jquery,Jquery,我有如下HTML: <input type="text" name="hyouka_sha1_bi" class="class1 class2 ... classIWantToGet_1" ></td> <input type="text" name="hyouka_sha1_bi" class="class1 class2 ... classIWantToGet_2" ></td> 但我找不到任何元素。只有当我的输入有一个类名时,它才起作用
<input type="text" name="hyouka_sha1_bi" class="class1 class2 ... classIWantToGet_1" ></td>
<input type="text" name="hyouka_sha1_bi" class="class1 class2 ... classIWantToGet_2" ></td>
但我找不到任何元素。只有当我的输入有一个类名时,它才起作用
我如何才能做到这一点?您可以使用
注意:如果有另一个类的中间或结尾包含给定字符串,则这可能不起作用
对于任意数量的类,在下面的代码中,border将应用于所有以classIWantToGet\开头的类名称的输入
$(document).ready(function() {
$("input[class^='classIWantToGet'],input[class*=' classIWantToGet_']").css("border","1px solid");
})
这很难吗
Here is the working demo
In this example If input has a class starting with "classIWantToGet_" I am adding border for those input elements.
试试这个:
$("input[class*='classIWantToGet']").css("border","1px solid red");
检查这个
$(document).ready(function() {
$("input[class^='classIWantToGet'],input[class*=' classIWantToGet_']").css("border","1px solid");
})
Here is the working demo
In this example If input has a class starting with "classIWantToGet_" I am adding border for those input elements.
$("input[class*='classIWantToGet']").css("border","1px solid red");