Myscript 在我的本地主机上不工作,但如果在 jsfiddle 中就没问题

Myscript not working in my localhost but if in jsfiddle it's fine

我不知道我的代码有什么问题。如果我的脚本 运行 在 jsfiddle 中就没问题。但是如果在我的电脑(本地主机)上它不工作。

这是我的 jsfiddle:JSFIDDLE

这是我 运行 在我电脑里的脚本

<html>
<body>
<input id="nominal" type="text" />
<script>
$(function() {
    var money = 20000;

    $("#nominal").on("change keyup", function() {
        var input = $(this);

        // remove possible existing message
        if( input.next().is("form") )
            input.next().remove();

        // show message
        if( input.val() > money )
            input.after("<form method=\"post\" action=\"\"><input type=\"submit\" name=\"yes\" value=\"Yes\"><input type=\"submit\" name=\"no\" value=\"No\"></form>");
    });
});
</script>
</body>
</html>

您需要包含 jQuery 库才能使用 jQuery 函数:

把这个放在你的脚本标签上面:

<script   src="https://code.jquery.com/jquery-3.1.0.slim.js"   integrity="sha256-L6ppAjL6jgtRmfiuigeEE5AwNI2pH/X9IBbPyanJeZw="   crossorigin="anonymous"></script>

<script>
$(function() {
    var money = 20000;

    $("#nominal").on("change keyup", function() {
        var input = $(this);

        // remove possible existing message
        if( input.next().is("form") )
            input.next().remove();

        // show message
        if( input.val() > money )
            input.after("<form method=\"post\" action=\"\"><input type=\"submit\" name=\"yes\" value=\"Yes\"><input type=\"submit\" name=\"no\" value=\"No\"></form>");
    });
});
</script>

它将 jQuery 从 CDN 加载到您的页面。