Я пытаюсь выяснить, почему мой JavaScript, который создает элементы ввода на лету через DOM, доступен в Firefox, но не в IE 7 и не в 8.
У меня есть следующая функция, запускаемая, когда пользователь нажимаетbutton
function addEndPoint_intelDNS(){
pageCounter.addMethod("endpoint_count");
count = pageCounter.getendpoint_count();
//endpoint IP and hostname labels
var endpointIPText = document.createTextNode('Endpoint ' + count + ' IP: \u00a0');
var endpointHostText = document.createTextNode('\u00a0 Endpoint ' + count + ' Hostname: \u00a0 ');
var brNode = document.createElement('br');
//endpoint InputIPBox
var endpoint_IP_InputElement = document.createElement('input');
endpoint_IP_InputElement.setAttribute('type', 'text');
endpoint_IP_InputElement.setAttribute('id', 'endpoint_'+count+'_ip');
endpoint_IP_InputElement.setAttribute('name', 'endpoint_'+count+'_ip');
endpoint_IP_InputElement.setAttribute('maxlength', '15');
endpoint_IP_InputElement.setAttribute('onChange', 'resolveMe(this.value,\u0022endpoint_'+count+'_name\u0022, \u0022ip\u0022);');
//endpoint host inputbox
var endpoint_HOST_InputElement = document.createElement('input');
endpoint_HOST_InputElement.setAttribute('type', 'text');
endpoint_HOST_InputElement.setAttribute('id', 'endpoint_'+count+'_name');
endpoint_HOST_InputElement.setAttribute('name', 'endpoint_'+count+'_name');
endpoint_HOST_InputElement.setAttribute('size', '35');
endpoint_HOST_InputElement.setAttribute('onChange', 'resolveMe(this.value,\u0022endpoint_'+count+'_ip\u0022, \u0022name\u0022);');
//output
document.getElementById('intelDNS_endpoints_codeblock').appendChild(endpointIPText);
document.getElementById('intelDNS_endpoints_codeblock').appendChild(endpoint_IP_InputElement);
document.getElementById('intelDNS_endpoints_codeblock').appendChild(endpointHostText);
document.getElementById('intelDNS_endpoints_codeblock').appendChild(endpoint_HOST_InputElement);
document.getElementById('intelDNS_endpoints_codeblock').appendChild(brNode);
Пожалуйста, игнорируйте объект pageCounter, это просто объект, который отслеживает, сколько входных данных будет предоставлять пользователь.
Как вы можете видеть, есть атрибут события onChangeдобавлены в каждое из 2 входных текстовых полей (InputIPBox и host_inputbox). Они практически идентичны, поэтому я предоставлю одну из функций
function resolveMe(val, loc_id, type){
alert(val);
switch(type){
case "ip":
resolveIP2DNS(val, loc_id);
break;
case "name":
resolveDNS2IP(val, loc_id);
break;
}
}
function resolveIP2DNS(ip, loc){
doclocation = loc;
var ajaxRequest; //initialize ajax object
var browser = navigator.appName; //find the browser name
if(browser == "Microsoft Internet Explorer"){
/* Create the object using MSIE's method */
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
}
else{
/* Create the object using other browser's method */
ajaxRequest = new XMLHttpRequest();
}
// Create a function that will receive data sent from the server
ajaxRequest.onreadystatechange = function(){
if(ajaxRequest.readyState == 4)
{
// Get the data from the server's response
//what on this page is changing
var xmlRes=ajaxRequest.responseXML.documentElement;
try {
var dns = xmlRes.getElementsByTagName('DNS')[0].firstChild.nodeValue;
}catch (err){
dns = "Not Resolvable";
}
//output to location in page
document.getElementById(doclocation).value = dns;
}
}
ajaxRequest.open("GET", "/ajax.psp?ip2DNS=" + ip, true);
ajaxRequest.setRequestHeader('Content-Type', "text/xml");
ajaxRequest.send(null);
}
Страница ajax.psp работает отлично, и эта функция работает, когда вызывается длячасти моего сайта, так что я знаю, что он получает желаемые значения разрешения.
Так что я весьма озадачен, потому что он отлично работает в Firefox, но не в IE. Также в дальнейшем отладке я вижу, что событие onchangeникогда не переходит к первой функции в IE (следовательно, предупреждение никогда не срабатывает).
Дайте мне знать, что вывсе думают ...