JQuery类型错误e是未定义的问题 [英] JQuery Type-error e is undefined issue
本文介绍了JQuery类型错误e是未定义的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这段代码给了我一个错误:
This code is giving me an error:
var openPrayer = function(e) {
e.preventDefault();
var id = $(e.currentTarget).data('id');
var json = $.getJSON('/user/prayers/' + id);
var temp = new t($('#prayerTemp').html());
json.then(function(resp){
var modal = temp.render(resp[0]);
$('body').append(modal);
});
}
$('.open-prayer').on('click', openPrayer);
这是错误:
This is the error:
TypeError: e is undefined
我不知道我在哪里出错了,上面的代码将 JSON
响应加载到我在下面设置的模板中:
I don't know where I am going wrong, the code above loads a JSON
response into a template I've set up below:
<script type="t/template" id="prayerTemp">
<div class="prayer-modal">
<img src="/img/icons/heart_infographic_prayer.jpg" class="hearts"/>
<div class="prayer">
<h1>@{{=name}}</h1>
<p>@{{=body}}</p>
</div>
<span class="close-prayer">×</span>
</div>
</script>
非常感谢您的任何帮助。
Any help is much appreciated.
推荐答案
var id = e.currentTarget.id;
也可以。但是,如果你需要IE< 8兼容性使用jQuery解决方案或解决方案,请参阅 MDN
Works fine too. But if you need IE < 8 compatibility use jQuery solution or solution explained at MDN
这篇关于JQuery类型错误e是未定义的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文