HTML数据和看起来像一个数字的字符串 [英] HTML data and a string that looks like a number

查看:137
本文介绍了HTML数据和看起来像一个数字的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于这个html

 < div data-a =0123>< / div> 

这个js:

 的console.log($( 'DIV')的数据( 'A')); 

返回 123 。有没有什么办法可以不添加额外的字符并将其切割得到一个字符串 0123



Jsfiddle: http://jsfiddle.net/PXw2J/

解决方案

您可以绕过 data()并直接获取该属性:

 的console.log($( 'DIV')ATTR( '数据-A')。); 

演示

For this html

<div data-a="0123"></div>

this js:

console.log($('div').data('a'));

returns 123. Is there any way without adding extra-chars and cutting it to get a string 0123?

Jsfiddle: http://jsfiddle.net/PXw2J/

解决方案

You can bypass data() and grab the attribute directly:

console.log($('div').attr('data-a'));

Demo

这篇关于HTML数据和看起来像一个数字的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆