我在一个弹出页面(showModelessDialog)中,应用了以下.js文件,总是报错“当前页面的脚本发生错误”缺少对象。
哪位大哥能帮我看看,哪里出错了啊?谢谢var inputs = document.getElementsByTagName('input');
var textareas = document.getElementsByTagName('textarea');
var selects = document.getElementsByTagName('select');
var isIE = (document.all && window.ActiveXObject && !window.opera) ? true : false;function $(id)
{
return document.getElementById(id);
}function stopBubbling (ev)
{
ev.stopPropagation();
}function rInputs()
{
for (i = 0; i < inputs.length; i++)
{
if (inputs[i].type == 'radio')
{
inputs[i].className = 'transparent';
rRadios(i);
}
else if (inputs[i].type == 'checkbox')
{
inputs[i].className = 'transparent';
rCheckboxes(i);
}
else if ((inputs[i].type == 'text' || inputs[i].type == 'password') && inputs[i].getAttribute('rel') != 'no_init_style')
{
rTextPassword(i);
}
else if ((inputs[i].type == 'submit' || inputs[i].type == 'button') && inputs[i].getAttribute('rel') != 'no_init_style')
{
rSubmits(i);
}
}
}function rTextareas()
{
for (i = 0; i < textareas.length; i++){
if (textareas[i].getAttribute('rel') != 'no_init_style')
{
textareas[i].className = 'tag_textarea';
textareas[i].onblur = function()
{
this.className = 'tag_textarea';
}
textareas[i].onfocus = function()
{
this.className = 'tag_textarea_focus';
}
textareas[i].onmouseover = function()
{
if (this.className != 'tag_textarea_focus')
{
this.className = 'tag_textarea_hover';
}
}
textareas[i].onmouseout = function()
{
if (this.className != 'tag_textarea_focus')
{
this.className = 'tag_textarea';
}
}
}
}
}function rSubmits(i)
{
inputs[i].className = 'type_submit';
inputs[i].onmouseover = function()
{
this.className='type_submit_hover';
}
inputs[i].onmouseout = function()
{
this.className='type_submit';
}
}function rTextPassword(i)
{
inputs[i].className = 'type_text';
inputs[i].onblur = function()
{
this.className = 'type_text';
}
inputs[i].onfocus = function()
{
this.className = 'type_text_focus';
}
inputs[i].onmouseover = function()
{
if (this.className != 'type_text_focus')
{
this.className = 'type_text_hover';
}
}
inputs[i].onmouseout = function()
{
if (this.className != 'type_text_focus')
{
this.className = 'type_text';
}
}
}function rRadios(i)
{
radio_type = document.createElement('div');
radio_type.id = 'radio_' + inputs[i].name + '_' + inputs[i].id;
radio_type.className = 'type_radio';
if (inputs[i].checked)
{
radio_type.className = 'type_radio_checked';
}
radio_type.style.cursor = 'pointer';
radio_type.style.position = 'absolute';
radio_type.style.display = 'inline';
radio_type.style.zIndex = '998';
inputs[i].parentNode.insertBefore(radio_type, inputs[i]); radio_type.onmouseover = new Function("mouseOverRadios('" + radio_type.id + "')");
radio_type.onmouseout = new Function("mouseOutRadios('" + radio_type.id + "')");
radio_type.onclick = new Function("clickRadios(" + i + ",'" + inputs[i].name + "','" + inputs[i].id + "')");}function rCheckboxes(i)
{
checkbox_type = document.createElement('div');
checkbox_type.id = 'checkbox_' + inputs[i].name + '_' + inputs[i].id;
checkbox_type.className = 'type_checkbox';
if (inputs[i].checked)
{
checkbox_type.className = 'type_checkbox_checked';
}
checkbox_type.style.cursor = 'pointer';
checkbox_type.style.position = 'absolute';
checkbox_type.style.display = 'inline';
checkbox_type.style.zIndex = '998';
inputs[i].parentNode.insertBefore(checkbox_type,inputs[i]);
checkbox_type.onmouseover = new Function("mouseOverCheckboxes('" + checkbox_type.id + "')");
checkbox_type.onmouseout = new Function("mouseOutCheckboxes('" + checkbox_type.id + "')");
checkbox_type.onclick = new Function("clickCheckboxes(" + i + ",'" + inputs[i].name + "','" + inputs[i].id + "')");
}function mouseOverRadios(id)
{
if ($(id).className == 'type_radio')
{
$(id).className = 'type_radio_hover';
}
else if ($(id).className == 'type_radio_checked')
{
$(id).className = 'type_radio_checked_hover';
}
}function mouseOutRadios(id)
{
if ($(id).className == 'type_radio_hover')
{
$(id).className = 'type_radio';
}
else if ($(id).className == 'type_radio_checked_hover')
{
$(id).className = 'type_radio_checked';
}
}function mouseOverCheckboxes(id)
{
if ($(id).className == 'type_checkbox')
{
$(id).className = 'type_checkbox_hover';
}
else if ($(id).className == 'type_checkbox_checked')
{
$(id).className = 'type_checkbox_checked_hover';
}
}function mouseOutCheckboxes(id)
{
if ($(id).className == 'type_checkbox_hover')
{
$(id).className = 'type_checkbox';
}
else if ($(id).className == 'type_checkbox_checked_hover')
{
$(id).className = 'type_checkbox_checked';
}
}function clickRadios(i, name, id)
{
radioid = 'radio_' + name + '_' + id ;
for (n = 0; n < inputs.length; n++)
{
if (inputs[n].type == 'radio')
{
if (inputs[n].name == name)
{
$('radio_' + inputs[n].name + '_' + inputs[n].id).className = 'type_radio' ;
}
}
}
if ($(radioid).className == 'type_radio')
{
$(radioid).className = 'type_radio_checked_hover';
}
inputs[i].click();
}
function clickCheckboxes(i, name, id)
{
inputs[i].click();
checkboxid = 'checkbox_' + name + '_' + id;
if ($(checkboxid).className == 'type_checkbox_hover')
{
$(checkboxid).className = 'type_checkbox_checked_hover';
}
else if ($(checkboxid).className == 'type_checkbox_checked_hover')
{
$(checkboxid).className = 'type_checkbox_hover';
}
}window.onload = function(e)
{
bodyclick = document.getElementsByTagName('body').item(0);
rInputs();
rTextareas();
rSelects();
bodyclick.onclick = function()
{
for (i = 0; i < selects.length; i++)
{
$('select_info_' + selects[i].name).className = 'tag_select';
$('options_' + selects[i].name).style.display = 'none';
}
checkInputs();
}
}function checkInputs()
{
for (i = 0; i < inputs.length; i++)
{
if (inputs[i].type == 'checkbox')
{
checkboxid = 'checkbox_' + inputs[i].name + '_' + inputs[i].id;
if (inputs[i].checked == true)
{
if ($(checkboxid).className == 'type_checkbox_hover')
{
$(checkboxid).className = 'type_checkbox_checked_hover';
}
else
{
$(checkboxid).className = 'type_checkbox_checked';
}
}
else if (inputs[i].checked == false)
{
if ($(checkboxid).className == 'type_checkbox_checked_hover')
{
$(checkboxid).className = 'type_checkbox_hover';
}
else
{
$(checkboxid).className = 'type_checkbox';
}
}
}
else if (inputs[i].type == 'radio')
{
radioid = 'radio_' + inputs[i].name + '_' + inputs[i].id;
if (inputs[i].checked == true)
{
if ($(radioid).className == 'type_radio_hover')
{
$(radioid).className = 'type_radio_checked_hover';
}
else if ($(radioid).className == 'type_radio_checked_hover')
{
// Nothing to do.
}
else
{
$(radioid).className = 'type_radio_checked';
}
}
else if (inputs[i].checked == false)
{
$(radioid).className = 'type_radio';
}
}
}
}
function checkAllCheckboxs(form, prefix, stats)
{
for (var i = 0; i < form.elements.length; i++)
{
var e = form.elements[i];
if (e.name && e.type == 'checkbox' && (!prefix || (prefix && e.name.match(prefix))))
{
e.checked = stats;
}
}
}
哪位大哥能帮我看看,哪里出错了啊?谢谢var inputs = document.getElementsByTagName('input');
var textareas = document.getElementsByTagName('textarea');
var selects = document.getElementsByTagName('select');
var isIE = (document.all && window.ActiveXObject && !window.opera) ? true : false;function $(id)
{
return document.getElementById(id);
}function stopBubbling (ev)
{
ev.stopPropagation();
}function rInputs()
{
for (i = 0; i < inputs.length; i++)
{
if (inputs[i].type == 'radio')
{
inputs[i].className = 'transparent';
rRadios(i);
}
else if (inputs[i].type == 'checkbox')
{
inputs[i].className = 'transparent';
rCheckboxes(i);
}
else if ((inputs[i].type == 'text' || inputs[i].type == 'password') && inputs[i].getAttribute('rel') != 'no_init_style')
{
rTextPassword(i);
}
else if ((inputs[i].type == 'submit' || inputs[i].type == 'button') && inputs[i].getAttribute('rel') != 'no_init_style')
{
rSubmits(i);
}
}
}function rTextareas()
{
for (i = 0; i < textareas.length; i++){
if (textareas[i].getAttribute('rel') != 'no_init_style')
{
textareas[i].className = 'tag_textarea';
textareas[i].onblur = function()
{
this.className = 'tag_textarea';
}
textareas[i].onfocus = function()
{
this.className = 'tag_textarea_focus';
}
textareas[i].onmouseover = function()
{
if (this.className != 'tag_textarea_focus')
{
this.className = 'tag_textarea_hover';
}
}
textareas[i].onmouseout = function()
{
if (this.className != 'tag_textarea_focus')
{
this.className = 'tag_textarea';
}
}
}
}
}function rSubmits(i)
{
inputs[i].className = 'type_submit';
inputs[i].onmouseover = function()
{
this.className='type_submit_hover';
}
inputs[i].onmouseout = function()
{
this.className='type_submit';
}
}function rTextPassword(i)
{
inputs[i].className = 'type_text';
inputs[i].onblur = function()
{
this.className = 'type_text';
}
inputs[i].onfocus = function()
{
this.className = 'type_text_focus';
}
inputs[i].onmouseover = function()
{
if (this.className != 'type_text_focus')
{
this.className = 'type_text_hover';
}
}
inputs[i].onmouseout = function()
{
if (this.className != 'type_text_focus')
{
this.className = 'type_text';
}
}
}function rRadios(i)
{
radio_type = document.createElement('div');
radio_type.id = 'radio_' + inputs[i].name + '_' + inputs[i].id;
radio_type.className = 'type_radio';
if (inputs[i].checked)
{
radio_type.className = 'type_radio_checked';
}
radio_type.style.cursor = 'pointer';
radio_type.style.position = 'absolute';
radio_type.style.display = 'inline';
radio_type.style.zIndex = '998';
inputs[i].parentNode.insertBefore(radio_type, inputs[i]); radio_type.onmouseover = new Function("mouseOverRadios('" + radio_type.id + "')");
radio_type.onmouseout = new Function("mouseOutRadios('" + radio_type.id + "')");
radio_type.onclick = new Function("clickRadios(" + i + ",'" + inputs[i].name + "','" + inputs[i].id + "')");}function rCheckboxes(i)
{
checkbox_type = document.createElement('div');
checkbox_type.id = 'checkbox_' + inputs[i].name + '_' + inputs[i].id;
checkbox_type.className = 'type_checkbox';
if (inputs[i].checked)
{
checkbox_type.className = 'type_checkbox_checked';
}
checkbox_type.style.cursor = 'pointer';
checkbox_type.style.position = 'absolute';
checkbox_type.style.display = 'inline';
checkbox_type.style.zIndex = '998';
inputs[i].parentNode.insertBefore(checkbox_type,inputs[i]);
checkbox_type.onmouseover = new Function("mouseOverCheckboxes('" + checkbox_type.id + "')");
checkbox_type.onmouseout = new Function("mouseOutCheckboxes('" + checkbox_type.id + "')");
checkbox_type.onclick = new Function("clickCheckboxes(" + i + ",'" + inputs[i].name + "','" + inputs[i].id + "')");
}function mouseOverRadios(id)
{
if ($(id).className == 'type_radio')
{
$(id).className = 'type_radio_hover';
}
else if ($(id).className == 'type_radio_checked')
{
$(id).className = 'type_radio_checked_hover';
}
}function mouseOutRadios(id)
{
if ($(id).className == 'type_radio_hover')
{
$(id).className = 'type_radio';
}
else if ($(id).className == 'type_radio_checked_hover')
{
$(id).className = 'type_radio_checked';
}
}function mouseOverCheckboxes(id)
{
if ($(id).className == 'type_checkbox')
{
$(id).className = 'type_checkbox_hover';
}
else if ($(id).className == 'type_checkbox_checked')
{
$(id).className = 'type_checkbox_checked_hover';
}
}function mouseOutCheckboxes(id)
{
if ($(id).className == 'type_checkbox_hover')
{
$(id).className = 'type_checkbox';
}
else if ($(id).className == 'type_checkbox_checked_hover')
{
$(id).className = 'type_checkbox_checked';
}
}function clickRadios(i, name, id)
{
radioid = 'radio_' + name + '_' + id ;
for (n = 0; n < inputs.length; n++)
{
if (inputs[n].type == 'radio')
{
if (inputs[n].name == name)
{
$('radio_' + inputs[n].name + '_' + inputs[n].id).className = 'type_radio' ;
}
}
}
if ($(radioid).className == 'type_radio')
{
$(radioid).className = 'type_radio_checked_hover';
}
inputs[i].click();
}
function clickCheckboxes(i, name, id)
{
inputs[i].click();
checkboxid = 'checkbox_' + name + '_' + id;
if ($(checkboxid).className == 'type_checkbox_hover')
{
$(checkboxid).className = 'type_checkbox_checked_hover';
}
else if ($(checkboxid).className == 'type_checkbox_checked_hover')
{
$(checkboxid).className = 'type_checkbox_hover';
}
}window.onload = function(e)
{
bodyclick = document.getElementsByTagName('body').item(0);
rInputs();
rTextareas();
rSelects();
bodyclick.onclick = function()
{
for (i = 0; i < selects.length; i++)
{
$('select_info_' + selects[i].name).className = 'tag_select';
$('options_' + selects[i].name).style.display = 'none';
}
checkInputs();
}
}function checkInputs()
{
for (i = 0; i < inputs.length; i++)
{
if (inputs[i].type == 'checkbox')
{
checkboxid = 'checkbox_' + inputs[i].name + '_' + inputs[i].id;
if (inputs[i].checked == true)
{
if ($(checkboxid).className == 'type_checkbox_hover')
{
$(checkboxid).className = 'type_checkbox_checked_hover';
}
else
{
$(checkboxid).className = 'type_checkbox_checked';
}
}
else if (inputs[i].checked == false)
{
if ($(checkboxid).className == 'type_checkbox_checked_hover')
{
$(checkboxid).className = 'type_checkbox_hover';
}
else
{
$(checkboxid).className = 'type_checkbox';
}
}
}
else if (inputs[i].type == 'radio')
{
radioid = 'radio_' + inputs[i].name + '_' + inputs[i].id;
if (inputs[i].checked == true)
{
if ($(radioid).className == 'type_radio_hover')
{
$(radioid).className = 'type_radio_checked_hover';
}
else if ($(radioid).className == 'type_radio_checked_hover')
{
// Nothing to do.
}
else
{
$(radioid).className = 'type_radio_checked';
}
}
else if (inputs[i].checked == false)
{
$(radioid).className = 'type_radio';
}
}
}
}
function checkAllCheckboxs(form, prefix, stats)
{
for (var i = 0; i < form.elements.length; i++)
{
var e = form.elements[i];
if (e.name && e.type == 'checkbox' && (!prefix || (prefix && e.name.match(prefix))))
{
e.checked = stats;
}
}
}
{
bodyclick = document.getElementsByTagName('body').item(0);
rInputs();
bodyclick.onclick = function()
{
checkInputs();
}
}
就不报错了,请问什么原因啊?
这样初始化不就少了很多要素了:(
你要把
var inputs = document.getElementsByTagName('input');
var textareas = document.getElementsByTagName('textarea');
var selects = document.getElementsByTagName('select');
放到函数里面,因为初始化的时候并不执行这些变量
<script language=javascript>
var inputs = document.getElementsByTagName('input');
var textareas = document.getElementsByTagName('textarea');
var selects = document.getElementsByTagName('select');
/*类似如上语句中的这些控件如果是包含于某form表单之内,这种调用是有问题的,换成如下:*/
var inputs = document.your_form_name.elements('input');
var textareas = document.your_form_name.elements('textarea');
var selects = document.your_form_name.elements('select');</script>