超链接无法处理<input type =“button”

时间:2015-10-08 11:51:26

标签: javascript php html css

=“”

请参阅以下代码。

我正在使用搜索栏并添加了一些按钮。

只有搜索按钮的超链接才能正常工作。但其他按钮不会重定向其链接,而是重定向到搜索按钮的超链接。

没有搜索按钮,其他三个按钮将使用其添加的单独超链接。 你能帮忙解决一下吗?

查看代码

http://pastebin.com/uEJyyvsh

4 个答案:

答案 0 :(得分:1)

为什么要在表单中保留4个提交按钮。 搜索是唯一的提交按钮。将按钮类型的其余部分更改为仅按钮。

I)并且,添加onlick="location.href='Your URL'"。像这样,

<input type="button" style="background-color: red" value="Login" onclick="location.href='http://localhost/login/';">

II)在新标签页中添加onclick="javascript:window.open('http://www.facebook.com/', '_blank');">以便打开。

<input type="button" style="background-color: red" value="Facebook" onclick="javascript:window.open('http://www.facebook.com/', '_blank');">

1)锚标记中可以target="_blank"

2)使用提交按钮可以formtarget="_blank"

但是,这里不需要4个提交按钮。有关详细信息,请查看此Submit Button Form Attribute - W3 Schools

<div class="widget search_key" id="directory_search_location-5">
        <div class="widget-wrap widget-inside">
            <div class="search_nearby_widget what_fld_search">            
                <form style="position:relative;" action="http://localhost/wordpress/" id="searchform" class="searchform_5509 allinone" method="get" name="searchform_5509">
                    <input type="hidden" value="listing" name="post_type">
                    <input type="hidden" value="all" name="mkey[]">
                    <input type="text" size="100" placeholder="Looking For ..." class="searchpost placeholder" id="search_near-15100" name="s" value="" onkeypress="tmpl_insta_search_widget('searchform_5509')" onclick="tmpl_insta_search_widget('searchform_5509')">

                    <input type="hidden" value="a18247a9c8" name="t">
                    <input type="hidden" value="OR" class="sgo" name="relation">
                    <input type="submit" style="background-color: red" value="Search" onclick="tmpl_find_click(15100);" class="sgo">
                    <input type="button" style="background-color: red" value="Register" onclick="javascript:window.open('http://localhost/register/', '_blank');">
                    <input type="button" style="background-color: red" value="Login" onclick="javascript:window.open('http://localhost/login/', '_blank');">
                    <input type="button" style="background-color: red" value="Facebook" onclick="javascript:window.open('http://www.facebook.com/', '_blank');">
                </form>
            </div>
        </div>
</div>

如果你真的想去登录,注册,facebook页面.. 这样给。

<a href="Your URL Here">
    <input type='button' value="Login">
</a>

答案 1 :(得分:0)

您需要将输入按钮包装在锚标记内。那应该解决它。

实施例

<a href="http://localhost/register/" formtarget="_blank" ><input type="submit" style="background-color: red" value="Register"></a>

答案 2 :(得分:0)

实际上你不必使用href输入,你应该使用&#39; a&#39; tag。,没有这样的属性,但你可以像下面的代码一样输入链接,你的代码中有问题,你使用了一个表单多个提交动作

<form action="http://google.com">
    <input type="submit" value="Go to Google">
</form>

<input type="submit" value="Go to my link location" 
    onclick="window.location='/my/link/location';" /> 

答案 3 :(得分:0)

您可以使用此类代码链接页面。你必须删除一个标签

<input type="submit" value="Button Name" onclick="window.location.href='/pagename'">Continue</button>