开发者

How do you get a jQueryUI button click to cause a page redirect?

If I define a jQuery UI button for a search feature:

jQuery("#do_search").button();

How do I get a click of this button to cause a page redirect to:

/sear开发者_StackOverflowch


You can use button() on links also

<a href="/search" class="button">My link</>
$(".button").button();


Try this:

jQuery("#do_search").button().click( function() {
    window.location.href = "/search";
});


I'll assume "do_search" is a element. If this is the case, clicking the button would simply follow the link, no special action required.

If "do_search" is or or something similar, you'd have to write an event handler for the click action. Like:

$("#do_search").click(function() { location.href=... });

Though I guess that your search page require you to submit some information to it, so the server side code would search it. If this is the case, you'd have to make some modifications to the above code, or use a FORM.


I dont know jQuery UI so much but you could do a redirect in jQuery:

$('#do_search').click(function() {
  top.location.href = "/search";
});
But if you want to search for what you entered (in a text input field) you could do:
$('#do_search').click(function() {
    var search_value = $("#search_field").val();
    top.location.href = "/search?q=" + search_value;
});
...to submit the search.

If this doesn't work try putting the code into:

$(document).ready(function(){ ... });

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜