动态创建table,按回车键自动切换光标位置及金额统计Js代码实现

1.JS页面输出拼接的Table代码,参数来自于Ajax请求响应回来的Json数据

  $("#rightTipPayBackTb").append("<tr><td>" + successCount + "</td><td>" + datas.Data.WayBillCode + "</td><td><input type=\"text\" onkeydown='if(event.keyCode==13)Alt.nextFocus(this);' onKeypress='Alt.only_number()' onfocus='this.select()' onKeyUp='Alt.text_zero(this);Alt.TipPayBack.getTotal()' id=\"txt" + datas.Data.WayBillCode + "\" name=\"tipAmount\" value='" + datas.Data.TipAmount + "' /></td><td>" + datas.Data.QuidcoDirectoryName + "</td><td style='color:blue;' onclick='Alt.TipPayBack.removeTipPayBack(this)'>删除</td></tr>");

2.Function函数,altBase作为全局调用封装的js代码

  1. getTotal() 金额合计,根据实际业务代码自己编写;
  2. //增加按回车键实现代码 
    altBase.only_number = function () {
    if (event.keyCode < 45 || event.keyCode > 57) event.returnValue = false;
    }

  3. //控件为空则为0 chenww 2017-10-23
    altBase.text_zero = function (text) {
    if (text.value == '') {
    text.value = 0
    text.select();
     }
    }

  4. //下移光标 
    altBase.nextFocus = function (the) {
    var oo = document.getElementsByName(the.name);
    var isFocus = false;
    for (i = 0; i < oo.length; i++) {
    if (isFocus) {
    oo[i].focus();
    break;
     }
    if (oo[i] == the) {
    isFocus = true;
     }
     }
    }

 3.总结:以上是实现的核心的js代码,仅供参考;

posted @ 2017-10-24 14:26  〆海浔、深蓝(小武)  阅读(494)  评论(0编辑  收藏  举报