为何我在用javascript中的sql语句执行对数据库插入记录的操作时,明明只选择了一个记录,执行了一次循环,但是却插入了二条一样的记录呢?(如果我选择了二条记录,就会执行四次插入)请大神帮我检查一下,看javascript语句有没有错误。
语句如下,是一个按钮的点击事件的语句(红字部分就是插入的语句):
var location = this.options.location; //获取当前控件的位置
var cr = FR.cellStr2ColumnRow(location);
var col = cr.col; //列号
var ro = cr.row; //行号
var products = ;
var ordernums = ;
var ordernums1 = ;
var ordernums2 = ;
var $span = $('.fr-checkbox-checkon');
var $tds = $("td").has($span);
var $trs = $("tr").has($tds);
for(var i=1; i<$trs.length;i++){
var row = $("td:eq(0)",$($trs)).attr("row");
products.push(contentPane.getCellValue(2,row));
contentPane.curLGP.setCellValue(1, ro+1+i,contentPane.getCellValue(2,row) );
ordernums.push(contentPane.getCellValue(6,row));
contentPane.curLGP.setCellValue(5, ro+1+i,contentPane.getCellValue(6,row) );
ordernums1.push(contentPane.getCellValue(7,row));
contentPane.curLGP.setCellValue(6, ro+1+i,contentPane.getCellValue(7,row) );
ordernums2.push(contentPane.getCellValue(8,row));
contentPane.curLGP.setCellValue(7, ro+1+i,contentPane.getCellValue(8,row) );
var t1 = contentPane.getCellValue(2,row);
var t2 = contentPane.getCellValue(6,row);
var t3 = contentPane.getCellValue(7,row);
var t4 = contentPane.getCellValue(8,row);
alert(t1+t2+t3+t4);
var p1= "'"+t1+"'" ;
var p2= "'"+t2+"'" ;
var p3= "'"+t3+"'" ;
var p4= "'"+t4+"'" ;
var sql2="insert into FGF进货表 ( DATE,category,product_id,product,SPECIFICATION,quantity,price) select date,category,product_id,product,specification,quantity,price from RM库存表 where specification="+ p2 + "and quantity="+ p3 + "and date="+ p1 + "and price="+ p4;
var k2='sql("RM",'+'"' + sql2 + '",1,1)';
alert(k2);
var b2=FR.remoteEvaluate(k2);
}