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

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

成都創(chuàng)新互聯(lián)是專業(yè)的頭屯河網(wǎng)站建設(shè)公司,頭屯河接單;提供網(wǎng)站設(shè)計制作、成都網(wǎng)站設(shè)計,網(wǎng)頁設(shè)計,網(wǎng)站設(shè)計,建網(wǎng)站,PHP網(wǎng)站建設(shè)等專業(yè)做網(wǎng)站服務(wù);采用PHP框架,可快速的進(jìn)行頭屯河網(wǎng)站開發(fā)網(wǎng)頁制作和功能擴(kuò)展;專業(yè)做搜索引擎喜愛的網(wǎng)站,專業(yè)的做網(wǎng)站團(tuán)隊,希望更多企業(yè)前來合作!

具體代碼如下

<!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)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,小編每天都會為大家更新不同的知識點。

分享標(biāo)題:JavaScript訂單操作小程序怎么實現(xiàn)
標(biāo)題來源:http://bm7419.com/article20/pscoco.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站營銷、標(biāo)簽優(yōu)化小程序開發(fā)、移動網(wǎng)站建設(shè)網(wǎng)站改版、電子商務(wù)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都做網(wǎng)站