溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

JavaScript訂單操作小程序怎么實現(xiàn)

發(fā)布時間:2022-05-20 10:44:46 來源:億速云 閱讀:104 作者:zzz 欄目:大數(shù)據(jù)

這篇文章主要介紹“JavaScript訂單操作小程序怎么實現(xiàn)”的相關(guān)知識,小編通過實際案例向大家展示操作過程,操作方法簡單快捷,實用性強(qiáng),希望這篇“JavaScript訂單操作小程序怎么實現(xiàn)”文章能幫助大家解決問題。

具體代碼如下

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
  <style>
    table {
      text-align: center;
    }
  </style>
  <script>
    function delRow(id) {
      //取得要刪除的那一行
      var row = document.getElementById(id);//按照id來找到行
      var table = document.getElementById('mytb');
      table.deleteRow(row.rowIndex);//按照行的索引刪除某行的內(nèi)容
    }
    function addrow() {
      var mytb = document.getElementById('mytb');
      var index = mytb.rows.length - 1;//取得插入目標(biāo)索引,某行
      var row = mytb.insertRow(index);//把行插入到某個位置,插入某行
      var id = 'row' + row.rowIndex;//拼接id
      row.setAttribute('id', id);//設(shè)置id
      var td0 = row.insertCell(0);//td0創(chuàng)建一個單元格
      td0.innerHTML = "好看耐用超耐磨沙發(fā)兩件套";//設(shè)置td0的內(nèi)容
      var td1 = row.insertCell(1);
      td1.innerHTML = row.rowIndex;//把行的索引賦給td1的內(nèi)容
      var td2 = row.insertCell(2);//把td2插入在某個單元格里面
      td2.innerHTML = '<input type="button" value="刪除" onclick="delRow(\'' + id + '\')">' +
        '<input type="button" value="修改" id="update" onclick="update(\'' + id + '\')">';
    }
    function update(id) {
      var row = document.getElementById(id);
      var td1 = row.cells[1];
      var v = td1.innerHTML;
      td1.innerHTML = '<input type="text"  value="' + v + '">';
      row.cells[2].innerHTML = '<input type="button" value="刪除" onclick="delRow(\'' + id + '\')">' +
        '<input type="button" value="確定" id="update" onclick="comfirmrow(\'' + id + '\')">';
    }
    function comfirmrow(id) {
      var row=document.getElementById(id);
      var td1=row.cells[1];//取得各行的第二個單元格
      var input=td1.firstChild;//取得input標(biāo)簽
      var v=input.value;//取得input的內(nèi)容
      td1.innerHTML=v;//把內(nèi)容賦給td1
      var td2=row.cells[2];
      td2.innerHTML = '<input type="button" value="刪除" onclick="delRow(\'' + id + '\')">' +
        '<input type="button" value="修改" id="update" onclick="update(\'' + id + '\')">';
    }
  </script>
</head>
<body>
<table border="1" cellspacing="0" cellpadding="0" id="mytb">
  <tr>
    <td>商品名</td>
    <td>數(shù)量</td>
    <td>操作</td>
  </tr>
  <tr id="del1">
    <td>好看耐用超耐磨沙發(fā)兩件套</td>
    <td>24</td>
    <td><input type="button" value="刪除" onclick="delRow('del1')"><input type="button" value="修改"></td>
  </tr>
  <tr>
    <td colspan="3"><input type="button" value="增加訂單" onclick="addrow()"></td>
  </tr>
</table>
</body>
</html>

關(guān)于“JavaScript訂單操作小程序怎么實現(xiàn)”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識,可以關(guān)注億速云行業(yè)資訊頻道,小編每天都會為大家更新不同的知識點。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI