document.ready在同一页上禁用其他功能

document.ready disables other function if on the same page

本文关键字:其他 功能 一页 ready document      更新时间:2023-09-26

我有两个函数可以完美地工作,除非我把它们放在同一页上。

函数1:-这将调用php来更新更改,并在与第二个位于同一页面时停止工作

<script>
    function save() {
        if (document.myform.notify1.checked == true) {
            var value1 = 1;
        } else {
            var value1 = 0;
        }
        if (document.myform.notify2.checked == true) {
            var value2 = 1;
        } else {
            var value2 = 0;
        }
        $.post('save_settings.php', {
            notify1: value1,
            notify2: value2
        });
        return false;
    };
</script>

函数2:-这个函数在结果的情况下调用一个列表,并且总是有效的

<script>
    $(document).ready(function () {
        $("#list").load("list.php");
        setInterval(function () {
            $.get('check.php', function (result) {
                if (result == 1) {
                    $("#list").load("list.php");
                }
            });
        }, 10000);
    });
</script>

这是调用函数save()的表单。

<form action="settings.php" enctype="multipart/form-data" name="myform" id="myform" method="post">
<input class="check" name="notify1" type="checkbox" id="notify1" <?php if($notify1 == "1") { echo "checked='"checked'""; } ?> value="1" onchange="save();"/>
<input class="check" name="notify2" type="checkbox" id="notify2" <?php if($notify2 == "1") { echo "checked='"checked'""; } ?> value="1" onchange="save();"/>
</form>
是的。。jquery做到了。替换为:if(document.myform.notify1.checked==true)与此if($("#notify1").is(':checked'))使其工作。
<script>
    function save() {
        if ($("#notify1").is(':checked')) {
            var value1 = 1;
        } else {
            var value1 = 0;
        }
        if ($("#notify2").is(':checked')) {
            var value2 = 1;
        } else {
            var value2 = 0;
        }
        $.post('save_settings.php', {
            notify1: value1,
            notify2: value2
        });
        return false;
    };
</script>

谢谢各位