我有一个输入,搜索者的谷歌网络和另一个搜索谷歌图像的输入。对于每个输入我都有按钮来淡入。搜索输入可以相同但搜索不同的网站吗?
这是我目前所拥有的一个小提琴:http://jsfiddle.net/kwC36/
要搜索我使用的网页:
<form action="http://google.com/search" method="get" class="websearch">
并搜索我使用的图像:
<form action="http://www.google.com/images?hl=en&q=" method="get" class="imagesearch">
非常感谢
答案 0 :(得分:1)
是的,您可以在表单上切换操作:
$('.web').click(function(){
$('form')[0].action = "http://google.com/search";
// do something
$('.websearch').fadeIn();
});
$('.image').click(function(){
$('form')[0].action = "http://www.google.com/images?hl=en&q=";
// do something
$('.websearch').fadeIn();
});
答案 1 :(得分:0)
<input type="submit" name="srch_images" value="Search Images">
<input type="submit" name="srch_google" value="Search Google">
if( isset($_POST['srch_images'] )
{
something();
}
else if( isset($_POST['srch_google']) )
{
something_else();
}
答案 2 :(得分:0)
将custom data attributes分配给按钮,以便表单操作可以是动态的:
<强> HTML:强>
<form id="search-form" action="" method="get" class="websearch">
<input id="search-field" type="text" class="searcher" name="" />
</form>
<input type="button" value="Search the web" class="search-btn" data-action="http://google.com/search" data-field-name="" />
<input type="button" value="Search images" class="search-btn" data-action="http://www.google.com/images?hl=en&q=" data-field-name="q" />
JQuery:
$('.search-btn').click(function(e){
e.preventDefault();
$('#search-field').attr('name',$(this).data('field-name'));
$('#search-form').attr('action',$(this).data('action')).submit();
});
答案 3 :(得分:0)
您可以使用相同的文本框搜索网页和图片。此外,不需要有两个表单标签。试试这个
$('.web').click(function(){
$('form').attr('action', "http://google.com/search").submit();
});
$('.image').click(function(){
$('form').attr('action', "http://www.google.com/images?hl=en&q=").submit();
});
答案 4 :(得分:0)
<强> HTML:强>
<form action="http://google.com/search" method="get" class="websearch">
<input type="text" class="searcher">
<input type="submit" value="Web Search" class="web">
<input type="submit" value="Image Search" class="image">
</form>
<强>使用Javascript:强>
$('.image').click(function() {
$(this).parent()
.attr('action', 'http://www.google.com/images?hl=en&q=');
});
应该这样做。