简体   繁体   中英

Two buttons in a form, Both called

Here's my ASP.NET form. When I click one button it calls both jQuery functions. It's probably a rudimentary HTML question but I'm not sure why:

<form id="form1" runat="server">
    <div id="testDialog">
    </div>

    <p><input type="button" id="invoke1" value="test 1" /></p>

    <input type="button" id="invoke2" value="test 2" />
</form>

<script type="text/javascript">
    $(function() {
        $("input:invoke1").click(function(){
            showSomething("testDialog");
        });

        $("input:invoke2").click(function(){
            showSomething2("test.aspx", options);
        });
    });
</script>

这些选择器不应该是

$("input#invoke1") and  $("input#invoke2")

try just

 $("#invoke1").click(function(){
        showSomething("testDialog");
    });

    $("#invoke2").click(function(){
        showSomething2("test.aspx", options);
    });

since id's should be unique, this should solve your problem

你甚至可以尝试

$("#invoke1")... and  $("#invoke2")...

the ID is unique for the document I see no need to include input with it, as follows

$("#invoke1").click()
$("#invoke2").click()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM