Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
HTML,使一个按钮将数据提交到另一个url?_Html - Fatal编程技术网

HTML,使一个按钮将数据提交到另一个url?

HTML,使一个按钮将数据提交到另一个url?,html,Html,以下是我的HTML: <form class="form-horizontal" method="post"> <div class="control-group"> <label class="control-label" for="inputEmail">Email</label> <div class="controls"> <i

以下是我的HTML:

<form class="form-horizontal" method="post">
        <div class="control-group">
            <label class="control-label" for="inputEmail">Email</label>
            <div class="controls">
                <input type="text" id="inputEmail" placeholder="Email">
            </div>
        </div>
        <div class="control-group">
            <label class="control-label" for="inputPassword">Password</label>
            <div class="controls">
                <input type="password" id="inputPassword" placeholder="Password">
            </div>
        </div>
        <div class="control-group">
            <div class="controls">
                <label class="checkbox">
                    <input type="checkbox"> Remember me
                </label>
                <button type="submit" class="btn btn-success">Sign in</button>
                <button class="btn btn-primary"> Make a new account </button>
            </div>
        </div>
    </form>

电子邮件
密码
记得我吗
登录
开一个新帐户
注意:万一有人想知道,它正在使用引导 图书馆

我有表单,它发布到login.php,但我希望按钮
创建一个新帐户
相同的数据发布到register.php


可能吗?如果是,如何设置?

表单的
属性设置为要将数据发送到的页面URL。


<form class="form-horizontal" method="post" action="register.php">
尝试以下操作:

在HTML中,为“创建新帐户”按钮添加onclick事件处理程序:

<form class="form-horizontal" method="post" id="myform">
        <div class="control-group">
            <label class="control-label" for="inputEmail">Email</label>
            <div class="controls">
                <input type="text" id="inputEmail" placeholder="Email">
            </div>
        </div>
        <div class="control-group">
            <label class="control-label" for="inputPassword">Password</label>
            <div class="controls">
                <input type="password" id="inputPassword" placeholder="Password">
            </div>
        </div>
        <div class="control-group">
            <div class="controls">
                <label class="checkbox">
                    <input type="checkbox"> Remember me
                </label>
                <button type="submit" class="btn btn-success">Sign in</button>
                <button class="btn btn-primary" onclick="javascript:register()"> Make a new account </button>
            </div>
        </div>
    </form>
如果这不起作用,您可以尝试:

function register() {
    var frm = document.getElementById("myform");
    frm.action = 'register.php';
    return true;
}
上述解决方案中的一个或两个应该适合您。首选第一种方法,因为它更干净

请将此作为起点,而不是复制粘贴解决方案,并遵循最佳开发实践

我有表单,它发布到login.php,但我希望按钮使一个新帐户将相同的数据发布到register.php

可能吗

在HTML5中,使用submit按钮上的属性


但浏览器支持可能还不太好。可以使用Polyfil自动将单击处理程序附加到此类按钮,并动态更改表单的
操作
属性来解决此问题。

当HTML中存在一个属性时,为什么要使用JS?ItayGal,表单上有两个提交按钮。询问者希望根据用户单击的按钮将同一表单提交到两个不同的URL。因此,我们正在为一个按钮使用默认的action属性值,并在单击第二个按钮时更新action属性。浏览器支持如下:TLDR:如果它是一个普通网站,您可能无法使用,但如果您有一个内部或受限用户的“web界面”,您有更大的能力要求使用最新的浏览器,这是最好的解决方案。@PauloSchreiner如果使用w3schools作为参考,你会被杀的,只是警告你。我想,事实上,我使用过的所有语言都是一样的,除了MS Razor页面,它似乎不起作用,因为它至少从browserIn.NET Core 3.1发布到同一个url,我能够设置asp页面和asp路由-。。。用于提交的输入标记上的属性。您需要创建一个shell cshtml文件,以便url生成工作。最终结果是一个formaction属性,它将表单路由到正确的Razor页面POST处理程序。
function register() {
    var frm = document.getElementById("myform");
    frm.action = 'register.php';
    return true;
}