获取使用Javascript或Jquery的自定义属性值
问题描述:
我怎样才能用JavaScript或jQuery的的自定义属性的值?
How can I get the value of a custom attribute using javascript or jquery?
如同
<strong id="the id" original-title="I NEED THIS">
我试着 .getAttribute()和ATTR()
..(Javascrupt&安培; jQuery的),没有成功的任何想法?
I've tried with .getAttribute() and attr()
..(Javascrupt & jQuery) without success any idea?
答
不要在ID中的空间。
和添加自定义属性,让你html格式无效。使用替代数据的属性。
And adding custom attributes make you html invalid. Use instead data-attributes.
<strong id="the_id" data-original-title="I NEED THIS">
$('#the_id').data('original-title');