简体   繁体   English

我需要使用“document.getElementById”吗?

[英]Do I need to use “document.getElementById”

I still haven't the got this code to work correctly in ie9. 我仍然没有得到这个代码在ie9中正常工作。 It works ok in Firefox though. 它在Firefox中运行正常。 Do I have to use "document.getElementById" for it to work in ie9? 我必须使用“document.getElementById”才能在ie9中工作吗? If so, where would it fit in? 如果是这样,它适合哪里?

function dbasetype(){

var dbasedata = document.forms[0]._dbase_name.value;
        dbasedata = dbasedata.toUpperCase();
        dbasedata = dbasedata.replace(/\s/g, "");

var _area = document.forms[0]._area;        
var _dbase_name = document.forms[0]._dbase_name;

if  (dbasedata.indexOf("UK_CONTACTS")==-1) {
        _area.value = _dbase_name.value;            
     }  else { setarea(); } 
     }

EDIT The above code updates a field (that controls the access for individuals) in a database when the save button is clicked. 编辑上面的代码在单击保存按钮时更新数据库中的字段(控制个人访问)。 It works ok in Firefox as I said previously but when this runs in ie9 the field that is supposed to be updated and is replaced with a blank and then the user loses access to the contact record. 正如我之前所说的,它在Firefox中运行正常但是当它在ie9中运行时应该更新的字段并被替换为空白然后用户失去对联系人记录的访问权限。

Your problem is that the IE has the stupid property that every ID is also a global (readonly) object. 您的问题是IE具有愚蠢的属性,每个ID也是一个全局(只读)对象。 You just have to rename your variable in your JavaScript like this: 您只需在JavaScript中重命名变量,如下所示:

function dbasetype() {
  var dbasedata = document.forms[0]._dbase_name.value;
  dbasedata = dbasedata.toUpperCase().replace(/\s/g, "");

  var x_area = document.forms[0]._area;        
  var x_dbase_name = document.forms[0]._dbase_name;

  if(dbasedata.indexOf("UK_CONTACTS")==-1) {
    x_area.value = x_dbase_name.value;            
  } else {
    setarea();
  } 
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM