欢迎您访问我爱IT技术网,今天小编为你分享的javascript教程:【jQuery $.data()方法使用注意细节】,下面是详细的讲解!
jQuery $.data()方法使用注意细节
function dataAttr( elem, key, data ) {
// If nothing was found internally, try to fetch any
// data from the HTML5 data-* attribute
if ( data===undefined && elem.nodeType===1 ) {
// rmultiDash=/([A-Z])/g
var name="data-" + key.replace( rmultiDash, "-$1" ).toLowerCase();
data=elem.getAttribute( name );
if ( typeof data==="string" ) {
try {
data=data==="true" ? true :
data==="false" ? false :
data==="null" ? null :
// Only convert to a number if it doesn't change the string
+data + ""===data ? +data :
rbrace.test( data ) ? jQuery.parseJSON( data ) :
data;
} catch( e ) {}
// Make sure we set the data so it isn't changed later
jQuery.data( elem, key, data );
} else {
data=undefined;
}
}
return data;
}
关于jQuery $.data()方法使用注意细节的用户互动如下:
相关问题:jquery data 怎么使用
答:jquery中data() 方法向被选元素附加数据,或者从被选元素获取数据。 jquery中data() 方法向被选元素附加数据,或者从被选元素获取数据。这使我们通过HTML自定义属性,操作数据,显得非常方便。通常我们也会通过给html自定义属性这样的做法,来存... >>详细
相关问题:state = $.data(jq,"combobox"),是什么意思,jq是...
答:你说的是对的,这是jQuery的data方法。 .data() 方法允许我们在DOM元素上绑定任意类型的数据,避免了循环引用的内存泄漏风险。 例子: $("body").data("foo", 52);//在body上绑定一个值key为foo值为52$("body").data("bar", { myType: "test", co... >>详细
相关问题:处理Jquery返回的data数据
答:可以这样判断一下嘛: success:function(data){ $(data).each(function(id) { //这里面的$使用,貌似只能把data当作是XML处理 if($(this).attr('class')=="list_pic")//判断是不是list_pic类 console.log($(this)[0].outerHTML);//得到包含DIV标... >>详细
- 【firefox】firefox浏览器不支持innerText的解决
- 【Extjs】Extjs学习过程中新手容易碰到的低级错误
- 【clearInterval】js clearInterval()方法的定义
- 【dom】javascript dom追加内容实现示例-追加内容
- 【checkbox】让checkbox不选中即将选中的checkbox
- 【Array】js中更短的 Array 类型转换-类型转换
- 【append】append和appendTo的区别以及appendChil
- 【ExtJs】ExtJs 表单提交登陆实现代码-表单提交-
- 【addClass】javascript自定义的addClass()方法
- 【Event】jquery下为Event handler传递动态参数的
- 评论列表(网友评论仅供网友表达个人看法,并不表明本站同意其观点或证实其描述)
-
