简体   繁体   English

使用正则表达式选择具有相似ID的元素-jQuery

[英]Select element with similar id using regex - jquery

An example of the element I need to select. 我需要选择的元素示例。

$("#edit_profile_form_profile_person_affiliations_2_user");

Id is same but a number of the element will change. Id相同,但元素的数量将改变。 I want to select all elements. 我要选择所有元素。 Is this is possible with the id of elements? 元素ID是否可行?

$("[id^=edit_profile_form_profile_person_affiliations_]")

它将匹配以“ edit_profile_form_profile_person_affiliations_”开头的ID。

As answer above, 作为上面的答案,

$("[id^=edit_profile_form_profile_person_affiliations_]")

this is good to check if ID starts with 这很好检查ID是否以

and this to check for end if ID 并检查ID是否结束

$("[id$=_user]");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM