我怎么能在JQuery按钮中有一个文本字段,而不在进入文本字段时触发按钮呢 标题 $(文档).ready(函数(){ $(“#countButton”)。在(“单击”,函数()上){ 目标=$('#直到').prop(“值”); tl=(“”+目标)。长度; numberString=“”; 对于(var i=0;i

我怎么能在JQuery按钮中有一个文本字段,而不在进入文本字段时触发按钮呢 标题 $(文档).ready(函数(){ $(“#countButton”)。在(“单击”,函数()上){ 目标=$('#直到').prop(“值”); tl=(“”+目标)。长度; numberString=“”; 对于(var i=0;i,jquery,onclick,uibutton,textfield,Jquery,Onclick,Uibutton,Textfield,这是因为事件从输入字段(id:until)传播 只需捕获事件并停止传播。请参阅下面的代码 <!DOCTYPE html> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Title</title> <meta http-equiv="c

这是因为事件从输入字段(id:until)传播

只需捕获事件并停止传播。请参阅下面的代码

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="content-type" content="text/html; charset=UTF-8">
        <title>Title</title>
        <meta http-equiv="content-type" content="text/html; charset=UTF-8">
        <meta name="robots" content="noindex, nofollow">
        <meta name="googlebot" content="noindex, nofollow">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
        <script src="https://code.jquery.com/jquery-1.11.1.min.js"></script>
        <script src="https://code.jquery.com/ui/1.11.1/jquery-ui.min.js"></script>
        <script>
        $(document).ready(function () {
            $('#countButton').on("click", function(){
                target=$('#until').prop("value");
                tl=(""+target).length;
                numberString="";
                for(var i=0; i<=target; i++){
                    numberString+=((""+i).padStart(tl, '0'))+"<br />";
                }
                $("#numbers").html(numberString);
            });
        });</script>
    </head>
    <body>
    <button class="ui-button ui-widget ui-corner-all" id="countButton">Count from 0 to <label for="until"> <input id="until" value="20" style="width: 50px;" type="number" min="1" /> </label>!</button>
    <div id="numbers"></div>
</body>
</html>

标题
$(文档).ready(函数(){
$(“#countButton”)。在(“单击”,函数()上){
目标=$('#直到').prop(“值”);
tl=(“”+目标)。长度;
numberString=“”;

对于(var i=0;iThanks),这正是我所需要的。
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="content-type" content="text/html; charset=UTF-8">
        <title>Title</title>
        <meta http-equiv="content-type" content="text/html; charset=UTF-8">
        <meta name="robots" content="noindex, nofollow">
        <meta name="googlebot" content="noindex, nofollow">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
        <script src="https://code.jquery.com/jquery-1.11.1.min.js"></script>
        <script src="https://code.jquery.com/ui/1.11.1/jquery-ui.min.js"></script>
        <script>
        $(document).ready(function () {
            $('#countButton').on("click", function(){
                target=$('#until').prop("value");
                tl=(""+target).length;
                numberString="";
                for(var i=0; i<=target; i++){
                    numberString+=((""+i).padStart(tl, '0'))+"<br />";
                }
                $("#numbers").html(numberString);
            });
            $('#until').on("click", function(){
                event.stopPropagation();
            });
        });</script>
    </head>
    <body>
    <button class="ui-button ui-widget ui-corner-all" id="countButton">Count from 0 to <label for="until"> <input id="until" value="20" style="width: 50px;" type="number" min="1" /> </label>!</button>
    <div id="numbers"></div>
</body>
</html>