【问题标题】:Onclick events for button按钮的 Onclick 事件
【发布时间】:2017-07-24 07:44:48
【问题描述】:

我有两个按钮,保存按钮和删除按钮。我需要将 onclick 事件添加到两个按钮。删除按钮的 onclick 事件功能正在工作,但我不知道如何将 onclick 事件添加到我的保存按钮。

这是我的代码。

<div class="form-group last">
<div class="col-sm-offset-3 col-sm-9">
    <input class="btn btn-info" id="savebutton" type="submit" name="save"  value="Update" > 
    <input class="btn btn-default" id="delete" type="submit" name="delete" value="Delete" onclick="return confirm('Are you sure to delete?');"> 
</div>

我想要做的是当我点击保存按钮时,记录将被保存到数据库中,并且会显示一些警告框,如果我点击“确定”,它将返回上一页。

【问题讨论】:

    标签: html onclick


    【解决方案1】:

    我不知道为什么它对您不起作用或您到底在寻找什么,但它应该与您为删除所做的相同。检查sn-p :)

    function update(){
    //databases work to save
    alert("saved");
       //address to the page where to want to redirect
       location.href = "www.yoursite.com";
    }
    <div class="form-group last">
    <div class="col-sm-offset-3 col-sm-9">
        <input class="btn btn-info" id="savebutton" type="submit" name="save"  value="Update" onclick="update();"> 
        <input class="btn btn-default" id="delete" type="submit" name="delete" value="Delete" onclick="return confirm('Are you sure to delete?');"> 
    </div>

    【讨论】:

    • 我知道这可以正常工作,但我需要的是,当我在警报框上单击“确定”时,它会转到另一个页面
    • @user1120 不适合您?单击警告框中的确定按钮后,该页面应导航到其他页面。
    • 这个location.href = "www.yoursite.com";可以直接转php吗?
    猜你喜欢
    • 1970-01-01
    • 2018-01-09
    • 2020-10-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多