如何使用javascript移除/隐藏、更改输入按钮的标题


how to remove/hide ,change caption of input button using javascript?

我有几个输入按钮。我想对ajax调用的响应做以下事情:

1)remove input button for that specific button that was clicked initially
2)change background color input textbox from red to green
3)change caption of edit box to try again if ajax call failed  

我当前的代码正确地将值传递给函数,ajax正确地返回响应,但我不知道如何做以上三件事!我的目标是让用户知道,通过在输入框中进行以上三项更改,可以正确地更改数据。有人能告诉我怎么做吗。感谢

通过按下inputbox按钮调用的javascript:

<script>
function setNewValue(a) {
var text = $("#"+a);
var textboxvalue = text.val();
    var url = "./edit.php";
    $.post(url, {
        "method": "post",
        "rowId": a,
        "rowValue": textboxvalue,
    }, function(data) 
       {
          var ajaxResponse = data;
        //alert("success"+ajaxResponse);
            if(ajaxResponse.indexOf("SuccessEdit")>=0)
            {
              //remote the edit button
            } 
            else
            {
              //change caption of edit button to try again
            }
      })
    }
</javascript>

php部分,用于打印html表中的输入框:

$table3.="<tr>";
 $table3.="<td>" . $row['ID'] ."(".$totalRows. ")</td>";
 $table3.="<td bgcolor='"#FF0000'"><input type='"text'" id ='"". $row['ID'] ."'" name='"". $row['ID'] ."'" value='"typer here to edit'"><button onclick='setNewValue('"".$row['ID']."'")'>Edit this Row</button></td>";
 $table3.="<td>" . $row['imgPURL'] . "</td>";
 $table3.="<td>" . $row['imgUrl'] . "</td>";
 $table3.="<td>".$line."</td>";  echo "</tr>";
  1. 您没有向函数传递两个值
  2. 将其添加到调用中会得到函数中的对象

你的代码太乱了,我无法完全修复,但请尝试

var saveBut;
function setNewValue(but,a,b) {
  var saveBut=$(but);
  var url = "./edit.php";
  $.post(url, {
    "method": "post",
    "rowId": a,
    "rowValue": b,
  }, function(data) {
     var ajaxResponse = data;
    //alert("success"+ajaxResponse);
     if(ajaxResponse.indexOf("SuccessEdit")>=0) {
       saveBut.remove();
       saveBut.prevAll('input').addClass("valid");
     }
     else {
      saveBut.html("Try Again")
     }
 })
}

使用这个php仍然不会将任何值传递给"b"

<button onclick='setNewValue(this,'"".$row['ID']."'")'>
function setNewValue(a,b) {
    var edit_button=this;
    var input_area=$("#"+a);
    var url = "./edit.php";
    $.post(url, {
        "method": "post",
        "rowId": a,
        "rowValue": b,
    }, function(data) 
       {
          var ajaxResponse = data;
        //alert("success"+ajaxResponse);
            if(ajaxResponse.indexOf("SuccessEdit")>=0)
            {
               //remove the edit button
               edit_button.hide();
            } 
            else
            {
              //change caption of edit button to try again
             input_area.val("try again");
            }
      })
    }
</javascript>