jQuery selector regular expressions

前端 未结 10 2437
傲寒
傲寒 2020-11-21 22:36

I am after documentation on using wildcard or regular expressions (not sure on the exact terminology) with a jQuery selector.

I have looked for this myself but have

10条回答
  •  萌比男神i
    2020-11-21 23:36

    These can be helpful.

    If you're finding by Contains then it'll be like this

        $("input[id*='DiscountType']").each(function (i, el) {
             //It'll be an array of elements
         });
    

    If you're finding by Starts With then it'll be like this

        $("input[id^='DiscountType']").each(function (i, el) {
             //It'll be an array of elements
         });
    

    If you're finding by Ends With then it'll be like this

         $("input[id$='DiscountType']").each(function (i, el) {
             //It'll be an array of elements
         });
    

    If you want to select elements which id is not a given string

        $("input[id!='DiscountType']").each(function (i, el) {
             //It'll be an array of elements
         });
    

    If you want to select elements which name contains a given word, delimited by spaces

         $("input[name~='DiscountType']").each(function (i, el) {
             //It'll be an array of elements
         });
    

    If you want to select elements which id is equal to a given string or starting with that string followed by a hyphen

         $("input[id|='DiscountType']").each(function (i, el) {
             //It'll be an array of elements
         });
    

提交回复
热议问题