How to select an input element by value using javascript?

后端 未结 7 830
被撕碎了的回忆
被撕碎了的回忆 2020-12-08 19:41

I\'ve seen it\'s jquery equivalent:

$(\'input[value=\"something\"]\');

But how do you select it using pure javascript (no jQuery).

7条回答
  •  旧巷少年郎
    2020-12-08 20:06

    with ie6-ie7-ie8

    function getInputsByValue(value)
    {
        var allInputs = document.getElementsByTagName("input");
        var results = [];
        for(var x=0;x

    with modern browsers ie9+ (? not sure for ie9 actually) :

    document.querySelectorAll("input[value=something]");
    

提交回复
热议问题