首页 新闻 会员 周边 捐助

点击添加按钮时 怎么动态生成 tr td 并把str str2, str3 放到动态生成的tr 里面

0
[已解决问题] 解决于 2018-10-15 12:38

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
   
    <title>My JSP 'Yss-add.jsp' starting page</title>
   
 <meta http-equiv="pragma" content="no-cache">
 <meta http-equiv="cache-control" content="no-cache">
 <meta http-equiv="expires" content="0">   
 <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
 <meta http-equiv="description" content="This is my page">
 <!--
 <link rel="stylesheet" type="text/css" href="styles.css">
 -->
    <script type="text/javascript" src="js/jquery-1.10.2.min.js"></script>
    <script type="text/javascript" src="js/jquery.easyui.min.js"></script>
    <link rel="stylesheet" href="js/default/easyui.css" type="text/css"></link>
    <link rel="stylesheet" href="js/icon.css" type="text/css"></link>
  </head>
 
  <body>
           选择供货商:<select id="se" onchange="bb()"></select>
           <a id="btn" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-add'" onclick="add()">添加</a>
                <table id="dg" class="easyui-datagrid" title="商品表"></table>
        <form style="background-color:red;width:500;height:200">
        <table id="table22">
            <tr>
                <td>编号</td>
                <td>名称</td>
                <td>价格</td>
             </tr>
           
          </table>
        </form>
  </body>
</html>
<script>
var url="";
  $.ajax({
   url:'xialai.action',
   type:'post',
   dataType:'json',
     async:false,
   success:function(data){
   var Str="";
   //alert(data[2])
    for(i=0;i<data.length;i++){
     Str+="<option value="+data[i].SHID+">"+data[i].SHNAME+"</option>";
    }
    $("#se").html(Str);
      }
  }) 

        
        function bb(){
               var aa=$('#se').val();
                 $('#dg').datagrid({
                 url:'car.action?shid='+aa,
                //EnableHeaderVisualStyles:false,
                 //singleSelect:true,//只能单选
                 fitColumns:true,
                 columns:[[  
                  {field:'CARGOID',title:'商品ID',width:100},   
                  {field:'CARGONAME',title:'商品名称',width:100},
                  {field:'CARGOSUM',title:'商品数量',width:100,align:'right'},
                        ]]  
                     }); 
                       }   
        $(function(){
      $("#se").trigger("change");
     
     })
    
     function zj(){
            var a=parseInt($('#price').val());
            var b=parseInt($('#sl').val());
            var c=a*b;
            $('#jg').val(c);
            }
    
    
    function add(){
                   //得到被选中行的数据
             var item = $('#dg').datagrid('getSelections');
              for(var i=0;i<item.length;i++){
               Str+="<td><input value="+item[i].CARGOID+"></td>";
               Str2+="<td><input value="+item[i].CARGONAME+"></td>";
               Str3+="<td><input value="+item[i].CARGOSUM+"></td>";
               var tr = document.createElement("tr");
               tr.innerHTML = str+str2+str3;
            
              }
           
    }
</script>

一襟晚照的主页 一襟晚照 | 初学一级 | 园豆:11
提问于:2017-12-29 10:58
< >
分享
最佳答案
0

insertCell 添加行,行.innerHTML=str

奖励园豆:5
青语 | 小虾三级 |园豆:1000 | 2017-12-29 11:17

能写的详细点么   还是不怎么懂

一襟晚照 | 园豆:11 (初学一级) | 2017-12-29 20:03
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册