当前位置: 首页 > 图文教程 > 网络编程 > Javascript > IE支持的HTML元素的DISABLE属性在NETSCAPE4.76中的实现

Javascript
为调试JavaScript添加输出窗口的代码
Js 中debug方式
一些mootools的学习资源
JavaScript 精粹读书笔记(1,2)
CutePsWheel javascript libary 控制输入文本框为可使用滚轮控制的js库
数组Array进行原型prototype扩展后带来的for in遍历问题
javascript 鼠标拖动图标技术
比较搞笑的js陷阱题
js 自定义的联动下拉框
js 省地市级联选择
JavaScript 类似flash效果的立体图片浏览器
JavaScript Event学习第九章 鼠标事件
jQuery AJAX回调函数this指向问题
toString()一个会自动调用的方法
jQuery 文本框模拟下拉列表效果
关于页面被拦截的问题
javascript 解析url的search方法
一个XML格式数据转换为图表的例子
Javascript 获取链接(url)参数的方法[正则与截取字符串]
一些收集整理非常不错的JS效果代码

Javascript 中的 IE支持的HTML元素的DISABLE属性在NETSCAPE4.76中的实现


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-08-10   浏览: 122 ::
收藏到网摘: n/a

IE支持的html元素的disablenetscape4.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.0Netscape4.76下测试通过!

<html>

<body>

<form>

<br>Test:<input type="text" name="t1" onfocus="disableText(this)">

<br>Edit:<input type="edit" name="t2" onfocus="disableEdit(this)">

<br>Textarea:<textarea name="t3" onfocus="disableTextarea(this)"></textarea>

<br>Password: <input type="password" name="t4" onfocus="disablePassword(this)">

<br>Radiobutton: <input type="radio" name="t5" onmousedown="return disableRadio(this)">

<br>Checkbox: <input type="checkbox" name="t6" onclick="return disableCheck(this)">

<br>Defaul disabled Checkbox: <input type="checkbox" disabled name="t8" onmousedown="return disableCheck2(this)">

<br>Select:

<select name="t7" onchange=" ChangeSelect(this)">

<option> one

<option> two

<option> three

<option> four

</select>

 

<br><input type="button" value="Enable/Disable" onClick="change()">

</form>

</body>

</html>

 

<script language="javaScript">

function disableText(obj)

{

if(obj.disabled)

obj.blur();

}

 

function disableEdit(obj)

{

if(obj.disabled)

obj.blur();

}

 

function disablePassword(obj)

{

if(obj.disabled)

obj.blur();

}

 

function disableTextarea(obj)

{

if(obj.disabled)

obj.blur();

}

 

function disableRadio(obj)

{

          if(obj.disabled)

          {

                    obj.checked=false;

                    return false;

           }

}

 

function disableCheck(obj)

{

        if(obj.disabled)

       {

                 obj.checked=false;

                 return false;

       }

}

 

function disableCheck2(obj)

{

              obj.disabled=true;

              if(obj.disabled)

              {

                      obj.checked=false;

                      return false;

               }

}

 

function ChangeSelect(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;

(这两种写法都是可以的)

      }

  

   }

 

}

 

function change()

{

document.forms[0].t1.disabled=!document.forms[0].t1.disabled;

 

document.forms[0].t2.disabled=!document.forms[0].t2.disabled;

document.forms[0].t3.disabled=!document.forms[0].t3.disabled;

document.forms[0].t4.disabled=!document.forms[0].t4.disabled;

document.forms[0].t5.disabled=!document.forms[0].t5.disabled;

document.forms[0].t6.disabled=!document.forms[0].t6.disabled;

document.forms[0].t7.disabled=!document.forms[0].t7.disabled;

 

document.forms[0].t1.value="";

document.forms[0].t2.value="";

document.forms[0].t3.value="";

document.forms[0].t4.value="";

 

document.forms[0].t5.checked=false;

document.forms[0].t6.checked=false;

document.forms[0].t7.value="";

for (var i=0; i<document.forms[0].t7.options.length; i++)

      {

        //document.forms[0].t7.options[i].selected = document.forms[0].t7.options[i].frozenStatus;

document.forms[0].t7.options[i].selected = false;

}

}

</script>