【问题标题】:Edit content onclick and submit to database PHP编辑内容 onclick 并提交到数据库 PHP
【发布时间】:2017-06-03 16:44:01
【问题描述】:

我正在尝试向数据库提交一个 textarea 表单。在 textarea 中,应该有一个标准的“请输入...”,然后当登录用户按下表单侧面的“编辑”按钮时,它应该使 textarea 可编辑。之后,它应该允许用户将内容提交到数据库中。

我无法编辑内容,因为它会在不点击提交按钮的情况下自动提交表单。

以下是我到目前为止所做的代码:

<div id="review">
<script>
        $('#edit').click(function(){
        $('#editable').removeAttr('readonly');
        $(this).text('submit');
        });
        </script>
<form action="" method="post">

        <textarea cols="50" rows="6" id='editable' readonly>Please post...!</textarea>
        <button id='edit'>Edit</button>

        <input type="submit" id="submit" name="submit" value="save" onclick="return confirm('Is the form filled out correctly?')"/> 

        </form>     
    </div>

【问题讨论】:

标签: html forms button submit edit


【解决方案1】:

去掉$(this).text('submit');

基本上,您是在告诉 textarea 变为可编辑,然后立即提交表单。

此外,您的侦听器可能会在该元素加载到 DOM 之前被调用。将函数放在 $(document).ready 函数中。如果这不起作用,请尝试以下操作。

将您的按钮更改为以下

<div id='edit' onclick="enableText()">Edit</div>

并将此脚本添加到您的页面

function enableText(){
    document.getElementById("editable").disabled = false;
};

【讨论】:

  • 嗨@Gezzasa,我已经尝试过了,但它也不起作用。该代码用于将编辑按钮更改为提交按钮。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多