通过javascript中的部分id字符串获取元素 [英] Getting elements by a partial id string in javascript
本文介绍了通过javascript中的部分id字符串获取元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下代码:
var inputs = document.getElementsByTagName("input");
for (var i = 0; i < inputs.length; i++) {
inputs[i].disabled = bDisabled;
}
我现在需要添加一些逻辑来禁用具有和的输入bib *形式的ID,其中bib可以是任何字符。我已经看到了其他问题,这是用jquery完成的,但我不能使用jquery只是简单的javascript。任何帮助将不胜感激。
I need to now add some logic to only disable the the inputs that have and Id of the form "bib*" where bib can be any character. Ive seen other questions where this is done with jquery but I cant use jquery just simple javascript. Any help would be appreciated.
谢谢
推荐答案
这很漂亮基本的东西。
var inputs = document.getElementsByTagName("input");
for (var i = 0; i < inputs.length; i++) {
if(inputs[i].id.indexOf("bib") == 0)
inputs[i].disabled = bDisabled;
}
这篇关于通过javascript中的部分id字符串获取元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文