target input by type and name (selector)

后端 未结 3 1431
野性不改
野性不改 2020-12-12 12:43

I need to change some checkbox inputs to hidden inputs for some but not all inputs on a page.



        
3条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-12 13:25

    You can combine attribute selectors this way:

    $("[attr1=val][attr2=val]")...
    

    so that an element has to satisfy both conditions. Of course you can use this for more than two. Also, don't do [type=checkbox]. jQuery has a selector for that, namely :checkbox so the end result is:

    $("input:checkbox[name=ProductCode]")...
    

    Attribute selectors are slow however so the recommended approach is to use ID and class selectors where possible. You could change your markup to:

     
     
    
    

    allowing you to use the much faster selector of:

    $("input.ProductCode")...
    

提交回复
热议问题