Jquery函数崩溃internet explorer

Jquery函数崩溃internet explorer,jquery,twitter-bootstrap,internet-explorer,Jquery,Twitter Bootstrap,Internet Explorer,我做了一个功能来清除我的模态,当它们关闭时,它在Firefox和google chrome上运行良好,但它会使internet explorer崩溃,并且不使用它不是一个选项。有什么方法可以更改它以便IE可以阅读它吗 $(".modal-body input").val("") (function () { $(".modal").on("hidden.bs.modal", function () { $(this).removeData(); }); });

我做了一个功能来清除我的模态,当它们关闭时,它在Firefox和google chrome上运行良好,但它会使internet explorer崩溃,并且不使用它不是一个选项。有什么方法可以更改它以便IE可以阅读它吗

$(".modal-body input").val("")
(function () {
    $(".modal").on("hidden.bs.modal", function () {
        $(this).removeData();
    });
});

第一行末尾缺少分号,应如下所示:

$(".modal-body input").val("");
$(".modal-body input").val("")(function () {
    $(".modal").on("hidden.bs.modal", function () {
        $(this).removeData();
    });
});
$(function () { //notice the $ at the start of the line
    $(".modal").on("hidden.bs.modal", function () {
        $(this).removeData();
    });
});
(function () { //notice the $ at the start of the line
    $(".modal").on("hidden.bs.modal", function () {
        $(this).removeData();
    });
})(); //notice the extra () here
没有分号就像使用返回的
$(“.modal body input”).val(“”
)像函数一样,就像它在同一行一样

更清楚的是,如果您的代码是这样放置的:

$(".modal-body input").val("");
$(".modal-body input").val("")(function () {
    $(".modal").on("hidden.bs.modal", function () {
        $(this).removeData();
    });
});
$(function () { //notice the $ at the start of the line
    $(".modal").on("hidden.bs.modal", function () {
        $(this).removeData();
    });
});
(function () { //notice the $ at the start of the line
    $(".modal").on("hidden.bs.modal", function () {
        $(this).removeData();
    });
})(); //notice the extra () here
并中断,因为
val()
不返回函数


此外,代码的第二部分(您在此处放置代码的方式)没有任何作用,您可能希望它在文档加载时执行,如下所示:

$(".modal-body input").val("");
$(".modal-body input").val("")(function () {
    $(".modal").on("hidden.bs.modal", function () {
        $(this).removeData();
    });
});
$(function () { //notice the $ at the start of the line
    $(".modal").on("hidden.bs.modal", function () {
        $(this).removeData();
    });
});
(function () { //notice the $ at the start of the line
    $(".modal").on("hidden.bs.modal", function () {
        $(this).removeData();
    });
})(); //notice the extra () here
或者在加载代码时立即执行,如下所示:

$(".modal-body input").val("");
$(".modal-body input").val("")(function () {
    $(".modal").on("hidden.bs.modal", function () {
        $(this).removeData();
    });
});
$(function () { //notice the $ at the start of the line
    $(".modal").on("hidden.bs.modal", function () {
        $(this).removeData();
    });
});
(function () { //notice the $ at the start of the line
    $(".modal").on("hidden.bs.modal", function () {
        $(this).removeData();
    });
})(); //notice the extra () here

你永远不会调用这个函数。这应该是
$(函数…
)吗?谢谢!在val中添加te分号使它工作了,因为我在$(document).ready(function(){非常感谢。这节省了我的时间,很高兴知道它工作了。作为建议,尝试使用一些linting工具,如eslint来帮助您保持代码质量。