对id以某个字符串开头的元素进行计数

Count elements that the id begins with a certain string

本文关键字:元素 开头 id 字符串      更新时间:2023-09-26

可能重复:
jQuery返回ID以某个字符串开头的元素

好的,假设我有以下元素:

<select id="state_id" value="20">test1</select>
<select id="state_id1" value="21">test2</select>
<select id="state_id2" value="22">test3</select>

在这种情况下,如何获取id以state_id开头的select标记的length()

我尝试过:$("^#state_id").length();,但没有成功。

有什么提示吗?

试试这个。。。

$('[id^=state_]').length