的jQuery选择器来区分单一和动态ID输入类型?

时间:2019-06-19 12:47:12

标签: jquery

如何使用jQuery区分以下类型的ID?

  1. id="sectionId_1"
  2. id="sectionId_1_1"

我尝试了以下方法:

$(".row").find("input[id^='sectionId_']").each(function(){

========

编辑:

    There are two types of pattern
    1. id="sectionId_'+i+'" (section) where i can be 0,1,2 etc
    2. id="sectionId_'+i+'_'+j+'" (subsection) where i and j can be 0,1,2 
    etc
    for the second case i & j relationship is somewhat like nested for loop

    I need to get the values of section and subsection separately in 
    different .each loop and put it in separate array as well

1 个答案:

答案 0 :(得分:-1)

我为查询打了个小提琴。

https://jsfiddle.net/op5uv6mg/5/

$(document).ready(function () {


$("div").find("input[id^='sectionId_']").css("border", "1px solid green");


$("div").find("input[id^='sectionId_1_']").css("border", "1px solid pink");


});