开发者

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开发者_JAVA技巧 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
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜