简体   繁体   English

jQuery类型错误e是未定义的问题

[英]JQuery Type-error e is undefined issue

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

I don't know where I am going wrong, the code above loads a JSON response into a template I've set up below: 我不知道我要去哪里错,上面的代码将JSON响应加载到我在下面设置的模板中:

<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">&times;</span>
    </div>
</script>

Any help is much appreciated. 任何帮助深表感谢。

instead of 代替

 var id = $(e.currentTarget).data('id');

use 采用

 var id = $(e.target).data('id');

its working fine. 它的工作正常。

if want to know more difference between e.currentTarget and e.target see here :- 如果想知道e.currentTargete.target之间的更多区别,请参见:-

Difference between e.target and e.currentTarget e.target和e.currentTarget之间的区别

var id = e.currentTarget.id;

Works fine too. 也可以。 But if you need IE < 8 compatibility use jQuery solution or solution explained at MDN 但是,如果您需要IE <8兼容性,请使用jQuery解决方案或MDN中说明的解决方案

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 类型错误:网络未定义 - Type-error : network is undefined 重复函数将导致类型错误不是函数 - Repeating function will result in type-error is not a function 您可能需要适当的加载程序来处理此文件类型错误 - You may need an appropriate loader to handle this file type-error JavaScript单例类型错误:为什么严格模式对此进行标记? - JavaScript singleton type-error: why does strict mode flag this? Redux-toolkit - extraReducer 中出现类型错误的原因可能是什么? - Redux-toolkit - What could be the reason for a type-error in an extraReducer? 尝试将获取请求从控制器模块导入到主应用程序时出现错误。 (类型错误:无法读取未定义的正确“获取”) - I get an error when I try to import a get request from a controller module to my main app. (Type-error : Cannot read proper 'get' of undefined) 生产中的神秘错误:“类型错误:e未定义” - Esoteric error in production: `Type Error: e is undefined` 在没有实例的情况下,在运行时创建函数构造函数会导致Uncaught类型错误 - Creating function constructor causes Uncaught type-error while compiling at runtime without instance 如何允许我的程序检测 keyCode 而不会在 Javascript 中出现类型错误? - How do I allow my program to detect keyCode without getting a type-error in Javascript? Material-UI(React):使用StyledComponents和TypeScript的访问主题导致类型错误 - Material-UI(React): Access theme with StyledComponents and TypeScript causes in Type-Error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM