JQuery按钮数据返回为Null
JQuery Button Data Returning As Null?
我有一个按钮,当我点击它时,我希望html对象(又名按钮)作为参数传递给另一个javascript函数。我希望javascript函数从按钮中的元素打印数据hi。
HTML按钮
<button type = "button" onclick = "whoIsRdns(this)" class="dns-information btn btn-xs btn-info pull-right" data-toggle="modal" data-target = "#whois_rdns_modal" data-path="{{ path( '_who_is_rdns', { 'peer': peer.number, 'ip': peer.mac } ) }}" data-hi = "hi2">
<i class="icon-search"></i>
</button>
JS函数(W/JQUERY)
function whoIsRdns(thisButton){
//Enable jQuery properties from the param of the HTML object
var btn = $(thisButton);
var test = btn.data('hi');
console.log('Value is ' + test);
}
为什么测试会返回null?
var btn = $("thisButton");
不应该是var btn = $(thisButton);
(没有引号)
只是一个打字错误
$("thisButton") !== $(thisButton);
去掉引号,这样您就不会寻找标记名为thisButton
的元素
var btn = $("thisButton");
需要
var btn = $(thisButton);
相关文章:
- Meteor方法在客户端返回null,在客户端运行的相同方法返回正确的值
- 相同的RegExp返回不同的结果-第一次是正确的结果,第二次是null
- php函数的ajax html$_POST值返回null
- 谷歌地图API-“;toGeoJson”;返回几何体为null的对象
- 是否可以 document.getElementsByTagName('head')[0] ever 返回 null
- Firebase:查询返回null
- 在浅层渲染的反应组件上,Enzyme为道具返回null
- javascript对象显示为null,但object.properties返回数据
- PHP's json_decode返回空字符串(不是NULL)
- jQuery Multiselect插件返回null长度(应为0?)
- 如何处理getElementById返回Null
- JavaScript中的RegExp返回null
- node.js mongojs findOne回调返回错误为null
- Javascript 中的 RegEx 返回 Null
- 加载时的getelementbyID返回null
- 谷歌脚本在第二次调用Gmail后返回null
- Indexeddb OpenCursor在特定键值上返回null
- Ajax响应返回null
- null 返回 by JavaScript 中的 getElementById 方法
- 与typeof运算符一起使用时,javascript null返回对象