Skip to content

Commit

Permalink
重构 selected:get 适配方法
Browse files Browse the repository at this point in the history
  • Loading branch information
RubyLouvre committed Nov 11, 2012
1 parent e5f7302 commit 89c66a3
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 28 deletions.
8 changes: 3 additions & 5 deletions attr.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ define("attr",["$support","$node"], function( support ){
var el = this[0], getter = valAdapter[ "option:get" ];
if ( !arguments.length ) {//读操作
if ( el && el.nodeType == 1 ) {
//处理select-multiple, select-one,option,button
var ret = (valAdapter[ getValType(el)+":get" ] ||
$.propAdapter[ "@default:get" ])( el, "value", getter );
return typeof ret === "string" ? ret.replace( rreturn, "" ) : ret == null ? "" : ret;
Expand Down Expand Up @@ -227,7 +226,7 @@ define("attr",["$support","$node"], function( support ){
"tabIndex:get": function( node ) {
//http://www.cnblogs.com/rubylouvre/archive/2009/12/07/1618182.html
var ret = node.tabIndex;
if( ret === 0 ){//-1给那些不该拥有它的元素,0是默认分配给那些表单元素与链接
if( ret === 0 ){//在标准浏览器下,不显式设置时,表单元素与链接默认为0,普通元素为-1
ret = rtabindex.test(node.nodeName) ? 0 : -1
}
return ret;
Expand Down Expand Up @@ -292,14 +291,13 @@ define("attr",["$support","$node"], function( support ){
//safari IE9 IE8 我们必须访问上一级元素时,才能获取这个值
if ( !support.optSelected ) {
$.propAdapter[ "selected:get" ] = function( node ) {
var parent = node
for( ;!parent.add; parent.selectedIndex, parent = parent.parentNode){};
for( var p = node;typeof p.selectedIndex != "number";p = p.parentNode){}
return node.selected;
}
}
if ( !support.attrInnateValue ) {
// http://gabriel.nagmay.com/2008/11/javascript-href-bug-in-ie/
//在IE6-8如果一个A标签,它里面包含@,并且没任何元素节点,那么它里面的文本会变成链接值
//在IE6-8如果一个A标签,它里面包含@字符,并且没任何元素节点,那么它里面的文本会变成链接值
$.propAdapter[ "href:set" ] = $.attrAdapter[ "href:set" ] = function( node, name, value ) {
var b
if(node.tagName == "A" && node.innerText.indexOf("@") > 0
Expand Down
54 changes: 31 additions & 23 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,40 +11,48 @@
background:lime;
}
</style>
<script src="mass.js"></script>
<script src="jquery1.82.js"></script>

   <script>

// document.expando = false;
$.require("ready,node,attr",function(){
var el = $("button")[0]
var attrs = el.attributes
for(var i =0,attr; attr = attrs[i++];){
if(attr.specified){
console.log(attr.specified +" attr.name "+attr.name )
}

}

})

if($.require){
// document.expando = false;
$.require("ready,node,attr",function(){
var el = $('form')[0];
var el = document.getElementsByTagName("form")[0]
alert(el.attributes["onclick"].value)
alert(el.getAttribute("action"))
alert(el.getAttribute("id"))
alert(el.getAttribute("name"))
alert(el.getAttribute("length"))
alert(el.getAttribute("xxx"))
alert(el.getAttribute("yyy"))
})
}else{

}
window.onload = function(){
var el = document.getElementById("bb");
alert( el.attributes["title"].specified )
}
</script>

   </head>
   <body>



<button value="正确的值" tabindex="iii" tabIndex="iiie">
<button value="正确的值" id="bb" tabindex="iii" tabIndex="iiie">
<span style="color:red;">错误的值</span>
</button>
<form>
<label id="eee">
<input >
</label>
<input type="checkbox" id="test-20110810-checkbox"/>test checked

<form action="#" >
<input id="name" >
<input id="action" >
<input name="id" >
<input name="length" >
<input id="xxx" >
<input id="yyy" >
</form>

   </body>

</html>
</html>

0 comments on commit 89c66a3

Please sign in to comment.