javascript - 两个按钮一种形式

标签 javascript php html forms dom-events

<?=form_open('blog/register');?> 
            <table>
                <tr>
                    <td><label for="register_name">Username : </label></td>
                    <td><input type="text" name="register_name" readonly="readonly" value="<?=$_POST['username']?>"/></td>                    
                </tr>
                <tr>
                    <td><label for="register_email">Email:</label></td>
                    <td><input type="text" name="register_email" readonly="readonly" value="<?=$_POST['email']?>"/></td>                
                </tr>                
                <tr>
                    <td><label for="register_password">Password:</label></td>
                    <td><input type="password" name="register_password" readonly="readonly" value="<?=$_POST['password']?>"/></td>                
                </tr>               
                <tr>
                    <td></td>
                    <td><input type="submit" value="Register" onclick="return true;"/></td>
                </tr>
                <tr>
                    <td></td>
                    <td>                     
                        <input type="button" value="Edit" onclick="window.location.replace('http://localhost/index.php?username='<?=$_POST['username']?>'&email='<?=$_POST['email']?>');return true;"/>
                    </td>
                </tr>
            </table>
        <?=form_close()?>

这是一个有两个按钮作为两个选择的表单,注册按钮将用户重定向到注册屏幕,而第二个按钮将引导用户到登录屏幕。它不起作用,有人可以给我一个提示或任何指示吗?

我单击第二个按钮,但没有任何反应。第一个按钮工作正常

最佳答案

尝试更换

<input type="button" value="Edit" onclick="window.location.replace('http://localhost/index.php?username='<?=$_POST['username']?>'&email='<?=$_POST['email']?>');return true;"/>

<input type="button" value="Edit" onclick="window.location.href = 'http://localhost/index.php?username=<?=$_POST['username']?>&email=<?=$_POST['email']?>';return true;"/>

我相信你混淆了一些引言。

为了澄清,我删除了你的 php 周围的单引号,因为我认为它们是不必要的,并在你不想要的地方切断了你的位置字符串。 您的代码生成的位置字符串是 'http://localhost/index.php?username=',这是不正确的。

更新
replace() 更改为 href

关于javascript - 两个按钮一种形式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9258427/

相关文章:

javascript - 镭错误 - 未知插件 "flow-comments"

javascript - 滚动时不可见的div

javascript - 表格中的 Google 饼图单值

html - 适合对象 : cover with percentages

javascript - 从 Javascript 对象获取值

javascript - 将字符串求和为数字

php - 在 Magento 中添加属性以关联可配置产品的产品

php - 根据 WooCommerce 中的购物车小计将特定应税运费成本设置为 0

html - Bootstrap 轮播标题没有响应? (HTML, CSS)

c# - 使用 HTML 5 和 ASP.NET MVC 5 的视频流