首页 > 解决方案 > 关于 jquery.ui.spinner 的查询:事件未引发

问题描述

我目前正在使用带有 jquery 版本 'jquery-ui-1.10.4.js' 的 'ui-spinner'

有一个按钮,其可见性取决于 ui-spinner。我可以通过在 ui-spinner 上引发 onchange/keypress/keydown 事件来设置可见性,但这仅在使用微调器箭头时才有效。如果我通过 ui-spinner 中的键盘输入任何数字,则按钮可见性不会得到更新,因为在这种情况下不会引发任何事件。仅当我在 ui-spinner 文本框中输入数字后单击屏幕上的其他任何位置时才会引发该事件,但我需要在我在 ui-spinner 文本框中输入数字时引发事件。

下面是用户界面: 用户界面

标签: jquery

解决方案


<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>spinner demo</title>
    <link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/smoothness/jquery-ui.css">
    <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
    <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
</head>
<body>

    
    <input id="spinner" onkeyup="ShowMessage(this.value)" />
    <input type="button" id="btnHitMe" value="Hit Me !" disabled />
    <label id="UpdateValue">ddd</label>

    <script>
        $("#spinner").spinner();
        function ShowMessage(value) {
            
                
            $("#btnHitMe").prop('disabled', !(value.length > 0));
            
            console.log(value);
            $("#UpdateValue").text(value.length);
        }
    </script>

</body>
</html>


推荐阅读