Permalink
Browse files

Update attr.js

添加hasAttr方法
  • Loading branch information...
1 parent 3004081 commit b9f626da118b0e9870024664e27824c0bc8b48a9 @RubyLouvre committed Jan 7, 2014
Showing with 9 additions and 2 deletions.
  1. +9 −2 attr.js
View
11 attr.js
@@ -148,7 +148,14 @@ define("attr", !! this.getComputedStyle ? ["node"] : ["attr_fix"], function($) {
"for": "htmlFor",
"http-equiv": "httpEquiv"
},
- prop: function(node, name, value) {
+ //判定用户有没有显式定义某属性
+ hasAttr: document.documentElement.hasAttribute ? function(el, attr){
+ return el.hasAttribute(attr)
+ } : function(el, attr){//IE67
+ var outer = el.outerHTML, part = outer.slice(0, outer.search(/\/?['"]?>(?![^<]*<['"])/));
+ return new RegExp("\\s" + prop + "\\b", "i").test(part);
+ },
+ prop: function(node, name, value) {
if($["@bind"] in node) {
if(node.nodeType === 1 && !$.isXML(node)) {
name = $.propMap[name.toLowerCase()] || name;
@@ -354,4 +361,4 @@ define("attr", !! this.getComputedStyle ? ["node"] : ["attr_fix"], function($) {
http://nanto.asablo.jp/blog/2005/10/29/123294
http://perl.no-tubo.net/2010/07/01/ie-%E3%81%AB%E3%81%8A%E3%81%91%E3%82%8B-setattribute-%E3%82%84-getattribute-%E3%82%84-removeattribute-%E3%81%8C%E3%81%A0%E3%82%81%E3%81%A0%E3%82%81%E3%81%AA%E4%BB%B6/
- */
+ */

0 comments on commit b9f626d

Please sign in to comment.