JS 生成的行 里边 每列都有文本框,如何实现每行的 单价*数量=总金额

w915 2011-05-22 12:26:54
JS 生成的行 里边 每列都有文本框,如何实现每行的 单价*数量=总金额 目前行插入实现了,如何获得当前行的 文本框值,用于计算, 鼠标点击事件!


var i = parseInt(document.getElementById("rowindex").value);
//alert(document.getElementById("rowindex").value);
var name = i + "";
var row = document.createElement("tr");
row.setAttribute("id", name);
row.style.background = "#FFFFCC";
row.style.height = 25;
row.style.textAlign = "center";

var cell = document.createElement("td");
//cell.appendChild(document.createTextNode(name));
var inputText = document.createElement("input");
inputText.setAttribute("type", "text");
inputText.setAttribute("size", "1");
inputText.setAttribute("name", "ii");
inputText.setAttribute("value", ii);
//inputText.setAttribute("runat", "server");
cell.appendChild(inputText);
row.appendChild(cell);
...全文
76 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
w915 2011-05-22
  • 打赏
  • 举报
回复
高手 吃饭去了吗???
ggxxkkll1 2011-05-22
  • 打赏
  • 举报
回复
luguo
w915 2011-05-22
  • 打赏
  • 举报
回复
已经解决了




function addrow(v1,v2,v3,v4,v5,v6,v7,v8,v9,v10,v11,v12,v13,v14)
{


var i = parseInt(document.getElementById("rowindex").value);
//alert(document.getElementById("rowindex").value);
var name = i + "";
// var
var row = document.createElement("tr");
row.setAttribute("id", name);
row.style.background = "#FFFFCC";
row.style.height = 25;
row.style.textAlign = "center";

var cell = document.createElement("td");
//cell.appendChild(document.createTextNode(name));
var inputText = document.createElement("input");
inputText.setAttribute("type", "text");
inputText.setAttribute("size", "1");
inputText.setAttribute("name", "ii");
inputText.setAttribute("value", i+1);
//inputText.setAttribute("runat", "server");
cell.appendChild(inputText);
row.appendChild(cell);

var cell = document.createElement("td");
//cell.appendChild(document.createTextNode(name));
var inputText = document.createElement("input");
inputText.setAttribute("type", "text");
inputText.setAttribute("size", "12");
inputText.setAttribute("name", "pname");
inputText.setAttribute("value", v13);
//inputText.setAttribute("runat", "server");
cell.appendChild(inputText);
row.appendChild(cell);

var cell = document.createElement("td");
//cell.appendChild(document.createTextNode(name));
var inputText = document.createElement("input");
inputText.setAttribute("type", "text");
inputText.setAttribute("size", "6");
inputText.setAttribute("name", "codes");
inputText.setAttribute("value", v1);
//inputText.setAttribute("runat", "server");
cell.appendChild(inputText);
row.appendChild(cell);

var cell = document.createElement("td");
//cell.appendChild(document.createTextNode(name));
var inputText = document.createElement("input");
inputText.setAttribute("type", "text");
inputText.setAttribute("size", "6");
inputText.setAttribute("name", "ccode");
inputText.setAttribute("value", v2);
cell.appendChild(inputText);
row.appendChild(cell);

var cell = document.createElement("td");
//cell.appendChild(document.createTextNode(name));
var inputText = document.createElement("input");
inputText.setAttribute("type", "text");
inputText.setAttribute("size", "3");
inputText.setAttribute("name", "nums"+i);
inputText.setAttribute("id", "nums"+name);
inputText.setAttribute("value", v3);
cell.appendChild(inputText);
row.appendChild(cell);

var cell = document.createElement("td");
//cell.appendChild(document.createTextNode(name));
var inputText = document.createElement("input");
inputText.setAttribute("type", "text");
inputText.setAttribute("size", "6");
inputText.setAttribute("name", "bprice");
inputText.setAttribute("id", "bprice"+name);
inputText.setAttribute("value", v4);
cell.appendChild(inputText);
row.appendChild(cell);

var cell = document.createElement("td");
//cell.appendChild(document.createTextNode(name));
var inputText = document.createElement("input");
inputText.setAttribute("type", "text");
inputText.setAttribute("size", "6");
inputText.setAttribute("name", "jine");
inputText.setAttribute("id", "jine"+name);
inputText.setAttribute("value", v5);
//inputText.setAttribute("onclick", "javascript:sum('nums+')");
inputText.onclick = function (){ sums(name); };
cell.appendChild(inputText);
row.appendChild(cell);

var cell = document.createElement("td");
//cell.appendChild(document.createTextNode(name));
var inputText = document.createElement("input");
inputText.setAttribute("type", "text");
inputText.setAttribute("size", "6");
inputText.setAttribute("name", "fprice1");
inputText.setAttribute("value", v6);
cell.appendChild(inputText);
row.appendChild(cell);

var cell = document.createElement("td");
//cell.appendChild(document.createTextNode(name));
var inputText = document.createElement("input");
inputText.setAttribute("type", "text");
inputText.setAttribute("size", "6");
inputText.setAttribute("name", "fjine1");
inputText.setAttribute("value", v7);
cell.appendChild(inputText);
row.appendChild(cell);

var cell = document.createElement("td");
//cell.appendChild(document.createTextNode(name));
var inputText = document.createElement("input");
inputText.setAttribute("type", "text");
inputText.setAttribute("size", "3");
inputText.setAttribute("name", "num");
inputText.setAttribute("value", v8);
cell.appendChild(inputText);
row.appendChild(cell);

var cell = document.createElement("td");
//cell.appendChild(document.createTextNode(name));
var inputText = document.createElement("input");
inputText.setAttribute("type", "text");
inputText.setAttribute("size", "3");
inputText.setAttribute("name", "numf1");
inputText.setAttribute("value", v9);
cell.appendChild(inputText);
row.appendChild(cell);

var cell = document.createElement("td");
//cell.appendChild(document.createTextNode(name));
var inputText = document.createElement("input");
inputText.setAttribute("type", "text");
inputText.setAttribute("size", "6");
inputText.setAttribute("name", "depot");
inputText.setAttribute("value", v10);
cell.appendChild(inputText);
row.appendChild(cell);
var cell = document.createElement("td");
//cell.appendChild(document.createTextNode(name));
var inputText = document.createElement("input");
inputText.setAttribute("type", "text");
inputText.setAttribute("size", "3");
inputText.setAttribute("name", "weight");
inputText.setAttribute("value", v11);
cell.appendChild(inputText);
row.appendChild(cell);

var cell = document.createElement("td");
//cell.appendChild(document.createTextNode(name));
var inputText = document.createElement("input");
inputText.setAttribute("type", "text");
inputText.setAttribute("size", "3");
inputText.setAttribute("name", "pack");
inputText.setAttribute("value", v12);
cell.appendChild(inputText);
row.appendChild(cell);

var cell = document.createElement("td");
//cell.appendChild(document.createTextNode(name));
var inputText = document.createElement("input");
inputText.setAttribute("type", "text");
inputText.setAttribute("size", "3");
inputText.setAttribute("name", "recode");
inputText.setAttribute("value", v14);
cell.appendChild(inputText);
row.appendChild(cell);

var deleteButton = document.createElement("input");
deleteButton.setAttribute("type", "button");
deleteButton.setAttribute("value", "删");
deleteButton.onclick = function (){ deleterow(name); };
cell = document.createElement("td");
cell.appendChild(deleteButton);
row.appendChild(cell);


i = i ++;
document.getElementById("sortList").appendChild(row);
//document.getElementById("add").value = "";
document.getElementById("rowindex").value = i + 1 + "";
}

//删除行
function deleterow(id)
{
if (id!=null)
{
var rowToDelete = document.getElementById(id);
var sortList = document.getElementById("sortList");
sortList.removeChild(rowToDelete);
}
}

function sums(x)
{
//var rs = document.getElementById(x).value;
{
// alert(x);
document.getElementById("jine"+x).value=(document.getElementById("nums"+x).value)*(document.getElementById("bprice"+x).value);
}

}


87,915

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧