跟进jquery的代码进行检查,发现问题出在下面的代码中:

if ( notxml ) {
name = name.toLowerCase();
hooks = jQuery.attrHooks[ name ] || ( rboolean.test( name ) ? boolHook : nodeHook );
}

此处将属性名变成了全小写,导致dom对象内置的属性无法取到值。

代码所在位置第2298行,

attr函数完整代码:

attr: function( elem, name, value, pass ) {
var ret, hooks, notxml,
nType = elem.nodeType; // don't get/set attributes on text, comment and attribute nodes
if ( !elem || nType === 3 || nType === 8 || nType === 2 ) {
return;
} if ( pass && jQuery.isFunction( jQuery.fn[ name ] ) ) {
return jQuery( elem )[ name ]( value );
} // Fallback to prop when attributes are not supported
if ( typeof elem.getAttribute === "undefined" ) {
return jQuery.prop( elem, name, value );
} notxml = nType !== 1 || !jQuery.isXMLDoc( elem ); // All attributes are lowercase
// Grab necessary hook if one is defined
if ( notxml ) {
name = name.toLowerCase();
hooks = jQuery.attrHooks[ name ] || ( rboolean.test( name ) ? boolHook : nodeHook );
} if ( value !== undefined ) { if ( value === null ) {
jQuery.removeAttr( elem, name );
return; } else if ( hooks && "set" in hooks && notxml && (ret = hooks.set( elem, value, name )) !== undefined ) {
return ret; } else {
elem.setAttribute( name, "" + value );
return value;
} } else if ( hooks && "get" in hooks && notxml && (ret = hooks.get( elem, name )) !== null ) {
return ret; } else { ret = elem.getAttribute( name );//此处取属性的方法对属性名称是大小写敏感的 // Non-existent attributes return null, we normalize to undefined
return ret === null ?
undefined :
ret;
}

测试环境 IE,FF

使用jquery 1.7 及以后的版本 attr 问题的更多相关文章

  1. Jquery 获取Checkbox值,prop 和 attr 函数区别

    总结: 版本 1.6 1.6 1.4 1.4 函数 勾选 取消勾选 勾选 取消勾选 attr('checked') checked undefined true false .prop('checke ...

  2. Jquery Uploadify3.21.与2.1版本 使用中存在的问题--记录三

    Jquery Uploadify是个上传插件. 2.1版本与3.2.1版本有很大区别,方法名跟参数变动较大 1.uploader:该属性是用来存放swf的路径,这个swf就是一个Flash的一个图标, ...

  3. js/jQuery判断浏览器名称、内核版本、浏览器壳

    1.js方法 /* 判断浏览器名称和版本 目前只能判断:ie/firefox/chrome/opera/safari 2012年5月16日23:47:08 浏览器内核UA:UA; 浏览器内核名称:NV ...

  4. 2、jQuery的基本概念-必看-版本-入口函数- jq对象和dom对象区别

    1.4. jQuery的版本 官网下载地址:http://jquery.com/download/ jQuery版本有很多,分为1.x 2.x 3.x 大版本分类: 1.x版本:能够兼容IE678浏览 ...

  5. jquery/js不支持ie9以下版本的方法或属性

    1.jquery的trim()去除字符串两边的空格,在ie5~8中不支持此方法.若想替换字符串所有的空格看使用replace()正则替换: var date=" 2014-1 0-  15 ...

  6. jquery及相关兼容插件的版本搭配

    1.jquery1.11.0 + jquery.validate.1.9.0.js + jquery.ui.1.10.4.js

  7. jquery.min.js v1.10.3版本autocomplete方法会在text前添加搜索出多少项的文本信息 要去除

    http://stackoverflow.com/questions/13011127/how-to-remove-change-jquery-ui-autocomplete-helper-text ...

  8. jquery中CheckBox的checked状态用attr()的问题

    写了一个脚本,点按钮时选中checkbox,前几次可以选中,多点几次发现checkbox并未选中,调试后发现checked状态根本没有改变,后在网上查证与attr()函数有关,后改为prop问题解决. ...

  9. jQuery RemoveAttr(checked)之后再Attr(checked)属性无效果的原因分析

    jQuery中attr()和prop()在修改checked属性时的区别 投稿:whsnow 字体:[增加 减小] 类型:转载   使用语句$.attr('checked',true),将复选框的属性 ...

随机推荐

  1. linux下安装PHP的redis扩展

    1.安装redis ①下载:https://github.com/phpredis/phpredis.git ②cd phpredis   进入目录 ③/usr/local/php/bin/phpiz ...

  2. poj 3304 计算几何

    大意: 是否存在一条直线,使所有线段在直线上的投影至少交与一点 思路: 转换为是否存在一条直线与所有的线段相交,做这条直线的垂线,那么垂线即为所求 **/ #include <iostream& ...

  3. IOS 取值控件(UIPicker)的使用方法

    1.简单地取值控件示例 我们要做的一个UITextFiled,当点击UITextFiled,出现一个UIPick取值的页面,可以选择性别,在viewDidLoad中写下 //sexPicker UIP ...

  4. photoshop自动切图

    自动切图 前面的话 随着photoshop版本的不断升级,软件本身增加了很多新的功能,也为切图工作增加了很多的便利.photoshop最新的版本新增了自动切图功能,本文将详细介绍photoshop的这 ...

  5. LintCode-比较字符串

    题目描述: 比较两个字符串A和B,确定A中是否包含B中所有的字符.字符串A和B中的字符都是 大写字母 注意事项 在 A 中出现的 B 字符串里的字符不需要连续或者有序. 样例 给出 A = " ...

  6. 带你一起Piu Piu Piu~

    单刀直入,今天要讲的是自己写的一个WPF动画例子.我们在看下最终效果~ 最近在重看WPF编程宝典2010,在练习第15章动画性能例子时有了些想法.原始例子如下:  原始例子(打包了整个15章的) 它是 ...

  7. Trie三兄弟——标准Trie、压缩Trie、后缀Trie

    1.Trie导引 Trie树是一种基于树的数据结构,又称单词查找树.前缀树,字典树,是一种哈希树的变种.应用于字符串的统计与排序,经常被搜索引擎系统用于文本词频统计.用于存储字符串以便支持快速模式匹配 ...

  8. [置顶] perl脚本中defined,exists和delete关键字的用法和区别

    刚学习perl脚本的时候,喜欢频繁使用defined关键字判断一个hash中某个key是否存在,后来程序出了问题才去perl官方文档查看关于defined关键字的准确使用方法.因此,这里我把perl中 ...

  9. hdu 5007 水 弦

    http://acm.hdu.edu.cn/showproblem.php?pid=5007 纯粹的联系String的substr 什么时候substr拦截比写短话 string te; int n; ...

  10. codeforces 559A(Gerald's Hexagon)

    Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u   Description Gera ...