Myscript在我的本地主机中不工作,但如果在jsfiddle中,它'It’很好

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

本文关键字:jsfiddle It 很好 主机 工作 我的 Myscript 如果      更新时间:2023-09-26
我不知道我的代码出了什么问题。如果我的脚本在jsfiddle中运行,那没关系。但如果在我的计算机(localhost(中它不工作。

这是我的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加载到您的页面中。