Permalink
Browse files

Update attr.js

fix option取value bug
  • Loading branch information...
1 parent 5a69301 commit 4413907e36f9b90581d9007b1687876c81afb8fb @RubyLouvre committed Apr 17, 2014
Showing with 10 additions and 4 deletions.
  1. +10 −4 attr.js
View
14 attr.js
@@ -287,11 +287,17 @@ define("attr", !! this.getComputedStyle ? ["node"] : ["attr_fix"], function($) {
};
}
//========================valHooks 的相关修正==========================
+ var roption = /^<option(?:\s+\w+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s>]+))?)*\s+value[\s=]/i
var valHooks = {
- "option:get": function(node) {
- var val = node.attributes.value;
- //黑莓手机4.7下val会返回undefined,但我们依然可用node.value取值
- return !val || val.specified ? node.value : node.text;
+ "option:get": function(){
+ //在IE11及W3C,如果没有指定value,那么node.value默认为node.text(存在trim作),
+ //但IE9-10则是取innerHTML(没trim操作)
+ if (node.hasAttribute) {
+ return node.hasAttribute("value") ? node.value : node.text.trim()
+ }
+ //specified并不可靠,因此通过分析outerHTML判定用户有没有显示定义value
+ return roption.test(node.outerHTML) ? node.value : node.text
+
},
"select:get": function(node, value, getter) {
var option, options = node.options,

0 comments on commit 4413907

Please sign in to comment.