如何在$(“ input”)。change(function(){});的时间之前等待特定的<script>;会完蛋吗?

时间:2019-09-05 07:43:13

标签: javascript jquery

我需要使用

的输出
$("input").change(function(){});

在页面上的其他脚本中使用。如何等待执行直到change()完成的时间?

2 个答案:

答案 0 :(得分:0)

在应等待时停止执行主要脚本,并在功能结束时继续执行。如果需要,将当前状态保存到变量中。

$("input").change(function(){
     //do callback stuff

     //...

     MainScript.continue();
});

答案 1 :(得分:0)

将其他脚本代码包装到函数中,并使用以下方法-

<html>

<head>
    <script src="jquery.min.js"></script>
</head>

<body>
    Test input:
    <input type="text" name="testinput" />

</body>

<script>
    $(document).ready(function() {
        $("input").change(callback, function() {
            console.log('inside the click');
            callback('1');
        });

        function callback(val) {
          // other script wrapped in callback..
          console.log('Value received:' + val);

        }

    });
</script>

</html>