IE支持的html元素的disable在netscape4.76中的实现
1. 相关的html元素
(1) text , edit , password , textarea
(2) radio , checkbox
(3) select
2. IE中的写法
(1) document.form_name.text_name.disabled = true;
document.form_name.edit_name.disabled = true;
document.form_name.password_name.disabled = true;
document.form_name.textarea_name.disabled = true;
(2) document.form_name.radio_name[i].disabled = true;
document.form_name.checkbox_name[i].disabled = true;
(3) document.form_name.select_name.disabled = true;
3. Netscape4.76中的写法
(1) document.form_name.text_name.disabled = true;
document.form_name.edit_name.disabled = true;
document.form_name.password_name.disabled = true;
在相应的text , edit , password , textarea 元素上添加对focus事件处理的方法:onfocus=”disableElements(this)”
function disableElements(obj)
{
if(obj.disabled)
{
obj.blur();
}
}
(2) document.form_name.radio_name[i].disabled = true;
document.form_name.checkbox_name[i].disabled = true;
在相应的radio , checkbox元素上添加对mousedown事件处理的方法:onclick=”return disableElements(this)”
function disableElements(obj)
{
if(obj.disabled)
{
obj.checked=false;
return false;;
}
}
(3) document.form_name.select_name.disabled = true;
在相应的select元素上添加对change事件进行处理的方法:onchange=”disableElements(this)”
function disableElements(obj)
{
if (obj.disabled)
{
for (var i=0; i<obj.options.length; i++)
{
obj.options[i].selected = obj.options[i].frozenStatus;
(obj.options[i].selected = false;这样写也可以.)
}
}
}
最后我附上一个例子,这个例子在IE6.0和Netscape4.76下测试通过!
<html>
<body>
<form>
<br>Test:<input type="text" name="t1" >
<br>Edit:<input type="edit" name="t2" >
<br>Textarea:<textarea name="t3" ></textarea>
<br>Password: <input type="password" name="t4" >
<br>Radiobutton: <input type="radio" name="t5" >
<br>Checkbox: <input type="checkbox" name="t6" >
<br>Defaul disabled Checkbox: <input type="checkbox" disabled name="t8" >
<br>Select:
<select name="t7" >
<option> one
<option> two
<option> three
<option> four
<