jQuery 中的按钮单击

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19243559/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 23:30:42  来源:igfitidea点击:

Button Click in jQuery

javascriptjqueryhtmlajax

提问by Sirakhil

Im new to jQuery. I want to use a button click event to raise an alert box. This is my code, but it does'nt seem to work. Help! please

我是 jQuery 的新手。我想使用按钮单击事件来引发警报框。这是我的代码,但它似乎不起作用。帮助!请

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
        <title>Jquery Basic</title>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
        <script>
            $(document).ready(function() {
                $('submit1').click(function() {
                    alert("JQuery Running!");
                )};
            });
        </script>
    </head>
    <body>
        <a>JQuery Test Page</a><br>
        <input id="submit1" type="button" value="Submit"/>
    </body>
</html>

回答by Rory McCrossan

You are missing the #from your idselector. Try this:

你缺少的#,从你的id选择。尝试这个:

$(document).ready(function(){
    $('#submit1').click(function(){
        alert("JQuery Running!");
    });
});

回答by Amit

Answer already posted by @Rory, but you can also try this

@Rory 已经发布了答案,但您也可以试试这个

$(document).ready(function(){
    $('#submit1').on('click',function(){
        alert("JQuery Running!");
    });
});

回答by Marcus Italo

if you want to get the value of input i "textbox" and put the value in paragraph "para1" it solves, if your doubt is. I have helped. :)

如果您想获取输入 i“文本框”的值并将该值放在“para1”段落中,则它可以解决,如果您有疑问的话。我有帮助。:)

$(document).ready(function(){
    $("#submit1").click(function() {
        alert($("#textbox").val());
        $("#para1").text($("#textbox").val());
    });
});

回答by ibrahim ozboluk

$(function(){
    $("#submit1").live('click',function() {
       alert("hi!");
    });
});

回答by Aashray

You are missing #before your id. You need to use #if you want to select based on idand .if you want to select based on css-class.

#在你的id. 您需要使用#,如果你想根据选择id.,如果你想根据选择css-class

Try $('#submit1').click(function(){.

试试$('#submit1').click(function(){