【问题标题】:2 buttons one form2个按钮一种形式
【发布时间】:2012-02-13 09:49:21
【问题描述】:
<?=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()?>

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

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

【问题讨论】:

  • “它不起作用”是什么意思?它现在做了什么,你认为它应该做什么?
  • 好的,我更新它以获得更好的清晰度
  • 您正在使用表格。您不应该使用表格进行布局。每次你的代码运行时,上帝都会杀死一只小猫。希望你开心。
  • @Truth 也许他喜欢炸小猫。)但无论如何,user1211355 错误控制台的输出是什么?我敢打赌,你的 javascript 错误控制台中有你的答案,而你只是没有检查它 :)
  • @Vyktor 我猜你刚刚为自己赢得了一杯不错的冰镇啤酒。 :)

标签: php javascript html forms javascript-events


【解决方案1】:

尝试替换

<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

【讨论】:

  • 你为什么建议replace() w3schools.com/jsref/jsref_replace.asp 他只使用一个参数...应该是windows.location.href=,不是吗? (只是问)我感觉你在函数调用结束时忘记了 '
  • 但是它根本没有解决我的问题,我按下第二个按钮它仍然是一样的,没有调用 javascript 方法
  • @Vyktor,好建议,我改变了答案。 href 确实是要走的路。我刚刚注意到引号问题并更正了,但实际上replace 也不是正确的函数调用。请注意,这是 user1211355 使用的,而不是我的直接建议。
【解决方案2】:

替换代码

 <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.replace('http://localhost/index.php?username=<?=$_POST['username']?>&email=<?=$_POST['email']?>');return true;"/>

【讨论】:

    猜你喜欢
    • 2012-12-29
    • 2020-02-18
    • 1970-01-01
    • 1970-01-01
    • 2018-01-19
    • 2015-04-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多