【问题标题】:disable text area after button click单击按钮后禁用文本区域
【发布时间】:2017-02-23 03:13:19
【问题描述】:

我有一个显示多个文本区域的模式,我想要禁用已提交的特定文本区域

我有这个 javascript 函数,但它不起作用,我将行 id 连接到 textarea id,以便我可以定位特定的 textarea。我不知道我哪里出错了,请帮忙。

function approveStatus(status){
       var nid = status;
       var note = 'APPROVE';
       var app = document.getElementById("approvenote");

       app.addEventListener("click", function(){document.getElementById("note-"+status).disabled = true;});

       $.ajax({
        type: "POST",
        url: "mod.note.php?n=add",
        data: "note="+note+"&nid="+nid
      });


     }

html

<textarea class="from-control" rows="4" cols="50" id="note-<?php echo $row1['objID']; ?>" 
                             name="note"></textarea>
                            <button type="button" class="btn-xs btn-warning"
                            onclick="makeStatus(<?php echo $row1['objID']; ?>)" id="submitnote" name="submitnote">Submit Note
                            </button>
                            </form>
                            <button type="button" class="btn-xs btn-info" 
                            onclick="approveStatus(<?php echo $row1['objID']; ?>)" id="approvenote" name="approvenote" >APPROVE</button>

php

$app = isset($_GET['n'])?$_GET['n']:'';
if($app=='add'){

        $remarks = $_POST['note'];
        $note_id = $_POST['nid'];

        $auth_user->lessonRemarks($remarks,$note_id);
        header("Location: admin.php");

}else{
    header("Location: admin.php");
}

php函数

public function lessonRemarks($remarks,$note_id){
        $stmt = $this->conn->prepare("UPDATE `objectives`   
            SET `status` = :remarks
            WHERE `objID` = :note_id");

        $stmt->bindparam(":remarks",$remarks);
        $stmt->bindparam(":note_id",$note_id);
        $stmt->execute();

        return $stmt;
    }

【问题讨论】:

  • 发布您的相关html 以及您在哪里调用此approveStatus
  • 您正在使用 onclick 以及为同一 ID 添加事件侦听器。所以使用 "document.getElementById("note-"+status).disabled = true;"而不是 "app.addEventListener("click", function(){document.getElementById("note-"+status).disabled = true;});"
  • @MichaelSeltene 完美回答先生!这就是我要找的,非常感谢
  • 欢迎。我很高兴我能帮上忙。我会把它作为答案。

标签: javascript jquery html ajax bootstrap-modal


【解决方案1】:

您正在使用 onclick 以及为同一 id 添加事件侦听器。所以使用 "document.getElementById("note-"+status).disabled = true;"而不是 "app.addEventListener("click", function(){document.getElementById("note-"+status).disabled = true;});"

【讨论】:

    【解决方案2】:

    为了简化,你需要像这样使用jQuery的.prop()函数:

    $('button').click(function(){
      $('#textarea').prop('disabled', true);
    });
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <textarea id="textarea"></textarea>
    <button>Disable</button>

    【讨论】:

      【解决方案3】:

      你的代码:

      app.addEventListener("click", function(){
          document.getElementById("note-"+status).readOnly = true; 
      });
      

      【讨论】:

        猜你喜欢
        • 2015-09-24
        • 1970-01-01
        • 2012-02-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-06-20
        • 1970-01-01
        • 2011-01-20
        相关资源
        最近更新 更多