is ID of html controls which called by javascript casesensitive or not

余生颓废 提交于 2019-12-11 05:55:54

问题


i have this control

 <input id="btnBackMP" type="button" value="<" onclick="BackGroup('MP') ;" 
  disabled="disabled" style="background-color: #BF0000; width: 28px;" />

inside backGroup Function i used this Code Line :

  document.getElementById('btnback' + Key).disabled = true; 

this line works fine on Web Dev but when i published my site on server (iis 7) this line stop working till i changed it to the following :

document.getElementById('btnBackMP'+ Key).disabled = true; 

any one have idea ?

thanks


回答1:


Have you changed in calling function argument too since before your are passing 'MP' as argument and using as key

<input id="btnBackMP" type="button" value="<" onclick="BackGroup() ;" 
  disabled="disabled" style="background-color: #BF0000; width: 28px;" />

and why do not you directly change to this line only :-

document.getElementById('btnBackMP').disabled = true; 



回答2:


Element id is case sensitive. The id must be unique but in theory you could use id="elementa" and id="elementA" in the same document to refer on two different nodes.

This is not recommended

Further details on https://developer.mozilla.org/en-US/docs/DOM/element.id




回答3:


The id attribute values are case-sensitive by HTML specifications; see e.g. HTML 4.01 on id. They are thus case-sensitive when used in JavaScript too. Note that the document.getElementById method queries the DOM, which must follow HTML conventions here.

So btnbackMP and btnBackMP are distinct id values. Your code seems to have another error too, as pointed out, but this might be just an issue in formulating the question. (I suppose the last code line was meant to have btnBack not btnBackMP.)



来源:https://stackoverflow.com/questions/13285669/is-id-of-html-controls-which-called-by-javascript-casesensitive-or-not

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!