Getting elements by a partial id string in javascript

前端 未结 3 1792
慢半拍i
慢半拍i 2021-01-02 02:07

I have the followng code:

var inputs = document.getElementsByTagName(\"input\");
for (var i = 0; i < inputs.length; i++) {
inputs[i].disabled = bDisabled;         


        
相关标签:
3条回答
  • 2021-01-02 02:21

    I haven't tried this myself, but would CSS style attribute selectors?

    document.getElementsByTagName('[id^=bib]');
    
    0 讨论(0)
  • 2021-01-02 02:22

    This is pretty basic stuff.

    var inputs = document.getElementsByTagName("input");
    for (var i = 0; i < inputs.length; i++) {
      if(inputs[i].id.indexOf("bib") == 0)
        inputs[i].disabled = bDisabled;
    }
    
    0 讨论(0)
  • 2021-01-02 02:22
    function CheckDynamicValue(partialid, value) {
    
        var re = new RegExp(partialid, 'g');
        var elems = document.getElementsByTagName('*'), i = 0, el;
        while (el = elems[i++]) {
            if (el.id.match(re)) {
                el.disabled = value;
            }
        }
    }
    
    0 讨论(0)
提交回复
热议问题