简体   繁体   English

模板中脚本标记的IE错误

[英]IE error with script tag in template

I have the following script tag inside my Handlebar/Mustache template : 我的车把/胡子模板中包含以下脚本标签:

<script type="text/javascript">
        $(function() {
            $(".enable-checkbox").click(function(e) {
                if ($(this).parent().attr("for") == "Webpage") {
                    $('#Webpage').attr("value", $(this).is(":checked")); // Set true/false.                    
                }                    
                if ($(this).parent().attr("for") == "Unsubscribe") {
                    $('#Unsubscribe').attr("value", $(this).is(":checked"));
                }
            });
        });
    </script>

This works perfectly in Chrome and FF. 这在Chrome和FF中完美运行。 However, on IE - I get an error: 但是,在IE上-我收到错误消息:

Error: Could not complete the operation due to error 80020101.

After some research I figured out that the above error is due to the script tag my template. 经过研究,我发现上述错误是由于模板的脚本标签引起的。 If I remove the script tag, it works in IE. 如果我删除了脚本标记,它将在IE中运行。

Can anyone suggest a way to get this working in IE? 谁能建议一种使此功能在IE中运行的方法?

PS: Moving the contents of the script tag into the outer/main page that loads this script is not an option. PS:将script标记的内容移到加载此脚本的外部/主页中不是一种选择。

You can create templates in your JavaScript directly (without the need for a script tag) 您可以直接在JavaScript中创建模板(无需脚本标签)

App.templates = {

    template1: "{{#stooges}}" +
               "<b>{{name}}</b>" +
               "{{/stooges}}",

    template2: "{{#shows}}" +
               "<b>{{title}}</b>" +
               "{{/shows}}"

};

And refer to your template like so: 并这样引用您的模板:

var output = Mustache.render(App.templates.template1, view);

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM