免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 11203 | 回复: 11
打印 上一主题 下一主题

[表单] 我要被IE搞疯了,readonly在ie中如何设置 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2005-12-08 16:52 |只看该作者 |倒序浏览
<script>
<!--
function setrw(id)
{
        var r = document.getElementById(id);
        r.removeAttribute("readonly");
        alert("readonly="+r.getAttribute("readonly"));
}
function setr(id)
{
        var r = document.getElementById(id);       
        r.setAttribute("readonly",true);
        alert("readonly="+r.getAttribute("readonly"));
}
function getr(id)
{
        var r = document.getElementById(id);       
        alert("readonly="+r.getAttribute("readonly"));
}

-->
</script>
<html>
<body>
<form name="myform" id="myform">
<table >
<tr>
<td width="300" height="200">
<input type="text" name="text" id="text" value="read"><br />
<input type="button" name="show" value="显示设置" onclick="getr('text')"><br />
<input type="button" name="r" value="设为只读" onclick="setr('text')"><br />
<input type="button" name="rw" value="设为读写" onclick="setrw('text')"><br />
<input type="reset" value="reset">
</td></tr></table>
<form>
</body>
</html>


在FF中没有任何问题,在ie6中不行呀.
我改来改去也不成,比如改成
setAttribute("readonly","true")
setAttribute("readonley",false")
等等办法,死活搞不定.郁闷呀.

[ 本帖最后由 HonestQiao 于 2005-12-13 14:30 编辑 ]

论坛徽章:
1
技术图书徽章
日期:2013-12-05 23:25:45
2 [报告]
发表于 2005-12-08 17:32 |只看该作者
getElementByName为好.

你在IE看看,你是否真的取到了对象而且可以操作

论坛徽章:
0
3 [报告]
发表于 2005-12-08 18:21 |只看该作者
用getElementsByName不起作用.而且要得用数组下标来访问,不爽.
有对象的,用alter可以看到readonly=什么
在ie中,显示为true,false之类

论坛徽章:
1
技术图书徽章
日期:2013-12-05 23:25:45
4 [报告]
发表于 2005-12-08 22:15 |只看该作者
看了很多资料和HTML的标准参考,readonly:设置了不可以改过来.

不过你可以把整个元素去掉在加入一个新的元素

论坛徽章:
0
5 [报告]
发表于 2005-12-08 22:50 |只看该作者

  1. r.removeAttribute("readonly");
  2. ---> r.readOnly = false;

  3. r.setAttribute("readonly",true);
  4. ---> r.readOnly = true;
复制代码

论坛徽章:
1
技术图书徽章
日期:2013-12-05 23:25:45
6 [报告]
发表于 2005-12-08 23:03 |只看该作者
原帖由 eudemon 于 2005-12-8 22:50 发表

  1. r.removeAttribute("readonly");
  2. ---> r.readOnly = false;

  3. r.setAttribute("readonly",true);
  4. ---> r.readOnly = true;
复制代码



没有效果,你自己可以在IE测试.

我通过了测试,也看了标准手册的

论坛徽章:
0
7 [报告]
发表于 2005-12-09 01:12 |只看该作者
5楼的,你没有测试吧?
就是FF,如果removeAtrribute后,再get也不是false,而是null.

可能是IE的不完善吧.版主,你在哪看的资料不能改变呀?我在w3查了下,可以呀,

哈哈,正在我发帖到刚才时,我突然再看了下w3c资料,搞定了!
原来要把readonly写成readOnly,哈哈!!!

好,我现在根据FF和IE的不同,把其中的细节说一下.根据W3C资料,readOnly是一个bool值.如果照此判断,IE遵循标准要严格些,FF则放宽了很多.

现在假设有一个input对象r,
对比:
方法或属性                                       IE                           FF
r.readOnly                                     正确                      正确
r.readonly                                      错误                     错误
r.getAtrribute("readonly")             正确                      正确
r.getAttribute("readOnly")             正确                     正确
r.setAtrribute("readonly",true)      错误,区分大小写     正确
r.setAtrribute("readOnly","")         错误,值必须true    正确
r.setAttribute("readOnly",true)      正确                     正确
r.setAttribute("readOnly",false)     正确                    正确
r.removeAttribute("readonly")       错误,区分大小写    正确
r.removeAttribute("readOnly")      正确                     正确
<input id="r">                                false                  null
<input id="r" readonly>                true                     ""
setAtrribute方法设为true后             true                     true
setAtrribute方法设为false后             false                   false

论坛徽章:
0
8 [报告]
发表于 2005-12-09 08:57 |只看该作者

这个可以 用'readOnly'

<html>
<head>
<script>
<!--
function setrw(id)
{
        var r = document.getElementById(id);
        r.removeAttribute("readOnly");
        alert("readonly="+r.getAttribute("readOnly"));
}
function setr(id)
{
        var r = document.getElementById(id);      
        r.setAttribute("readOnly",true);
        alert("readonly="+r.getAttribute("readOnly"));
}
function getr(id)
{
        var r = document.getElementById(id);      
        alert("readonly="+r.getAttribute("readOnly"));
}

-->
</script>
</head>
<body>
<form name="myform" id="myform">
<table >
<tr>
<td width="300" height="200">
<input type="text" name="text" id="text" value="read"><br />
<input type="button" name="show" value="显示设置" onclick="getr('text')"><br />
<input type="button" name="r" value="设为只读" onclick="setr('text')"><br />
<input type="button" name="rw" value="设为读写" onclick="setrw('text')"><br />
<input type="reset" value="reset">
</td></tr></table>
<form>
</body>
</html>

论坛徽章:
1
技术图书徽章
日期:2013-12-05 23:25:45
9 [报告]
发表于 2005-12-09 09:08 |只看该作者
奇怪,你看的什么地方的资料啊:

我看的:http://www.w3.org/TR/REC-html40/interact/forms.html#adef-readonly

[CI]表示大小写无关
  1. CI
  2. The value is case-insensitive (i.e., user agents interpret "a" and "A" as the same).
复制代码
  1. 17.12.2 Read-only controls
  2. Attribute definitions

  3. readonly [CI]
  4. When set for a form control, this boolean attribute prohibits changes to the control.
  5. The readonly attribute specifies whether the control may be modified by the user.

  6. When set, the readonly attribute has the following effects on an element:

  7. Read-only elements receive focus but cannot be modified by the user.
  8. Read-only elements are included in tabbing navigation.
  9. Read-only elements may be successful.
  10. The following elements support the readonly attribute: INPUT and TEXTAREA.

  11. How read-only elements are rendered depends on the user agent.

  12. Note. The only way to modify dynamically the value of the readonly attribute is through a script.

复制代码

论坛徽章:
1
技术图书徽章
日期:2013-12-05 23:25:45
10 [报告]
发表于 2005-12-09 09:42 |只看该作者
不过disabled这个参数是可以使用的
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP