对于select做ele.setAttribute(“value”,“xxxx”)与ele.value = ""的效果
2013-12-20 19:10
316 查看
先来段代码:
var s = document.createElement("select") ;
for(var i = 0 ; i < 5 ; i++){
var op = document.createElement("option") ;
s.appendChild(op) ;
}
//--------------now start test
alert(s.getAttribute("value")) ;//null
alert(s.value) ;//0
//-----set default option
s.setAttribute("value",3) ;//do't work
s.value = 3 ; //work
嗯,应该能说的很清楚了,但是原因嘛,不是特别理解啊;不是推荐DOM level 1 的setA ,getA吗,可是获取值与设置默认值怎么办呢,还是不行的~
var s = document.createElement("select") ;
for(var i = 0 ; i < 5 ; i++){
var op = document.createElement("option") ;
s.appendChild(op) ;
}
//--------------now start test
alert(s.getAttribute("value")) ;//null
alert(s.value) ;//0
//-----set default option
s.setAttribute("value",3) ;//do't work
s.value = 3 ; //work
嗯,应该能说的很清楚了,但是原因嘛,不是特别理解啊;不是推荐DOM level 1 的setA ,getA吗,可是获取值与设置默认值怎么办呢,还是不行的~
相关文章推荐
- <c:set var="root" value="${pageContext.request.contextPath}"></c:set>According to TLD or attribute d
- Attribute value request.getAttribute("xxxx") is quoted with " which must be
- __atribute__使用:关于_attribute__ ((used,__section__(".xxxx")))的理解
- 【iOS开发-98】文件分段下载:@“HEAD“和[request setValue:range forHTTPHeaderField:@"Range"]
- 解决程序运行异常: set_Interval(Int32 value):值"0"不是Interval的有效值
- 发现net-snmp的snmp_set_var_typed_value()函数的"缺陷"
- spring3 jsp页面使用<form:form modelAttribute="xxxx" action="xxxx">报错,附连接数据库的spring MVC annotation 案例
- ognl.OgnlException: target is null for setProperty(null,"XXXX"...)
- spring3 jsp页面使用<form:form modelAttribute="xxxx" action="xxxx">报错,附连接数据库的spring MVC annotation 案例
- request.setAttribute("result",username);是什么意思?
- When Element add attribute by the method "setAttribute",It can't work in IE
- 关于"The value for the useBean class attribute is invalid" 错误<转>
- wrong # args: should be "set varName ?newValue?"
- request.setAttribute("list",list);出现空指针
- Here's an example that shows how to enumerate through the features of a selection set, returning the value of each field in the attribute table except for the geometry colum.
- request.getSession().setAttribute("",..)和request.setAttribute("",...)的差别
- Attribute value is quoted with " which must be escaped when used within the value 问题解决
- JQuery $("#id").val(value); 给select选值不出现问题
- 发布订阅:SELECT失败,因为下列SET选项的设置不正确:'ANSI_PADDING'。请确确保SET选项正确无误,可以用于计算列上的索引视图和/或索引......"
- session.setAttribute("sessionName",Object);