简体   繁体   中英

How can I get the event to fire more than once.

Thanks for input, my 1st attempt at this. I can only get the buttons to work once, I would like them to work every time as user will change search terms and results in different frame.

$(document).ready(function(){

    $("#button1").click(function(){
        $('form#myForm').attr({action: "completed.php"});
        $('form#myForm').attr({target: "righty"});
        $('form#myForm').submit();
    });

    $("#button2").click(function(){
        $('form#myForm').attr({action: "search.php"});
        $('form#myForm').attr({target: "lefty"});
        $('form#myForm').submit();
    });

    $("#button3").click(function(){
        $('form#myForm').attr({action: "amazonsearch.php"});
        $('form#myForm').attr({target: "righty"});
        $('form#myForm').submit();
    });


});

HTML:

<form id="myForm" method="post">
    <input name="Query" type="text" value="$title" size="60">
    <input type="button" id="button1" value="Completed" />
    <input type="button" id="button2" value="More Like" />
    <input type="button" id="button3" value="Amazon" />
</form>

you don't need to use

<form id=\"myForm\" method=\"post\"> just <form id="myForm" method="post">

that applies to all

I made a jsfiddle demo (with slight tweaks to targets, names etc to get things to work in that environment) and it works for me in both Firefox 3.6 and Chrome. Click a button, form is submitted to target. Update the query, click same button again, the form is submitted to the same target again.

try using .live instead

$("#myObject").live('click', function() {

    // do things
});

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