jquery增加一行后下拉提示问题

weiba963 2016-12-02 05:07:28
有一个批量添加的页面.在项目输入框中输入项目关键字会自动下拉提示与关键字相关的项目,然后选中后,单价框中显示该项目的单价,输入数量自动计算出金额.
现在都可以用了.只是在批量增加一行之后.增加的那行,输项目关键字不会提示下拉.请哪位帮帮忙.看看JS.怎么融合起来让批量增加的在输入项目的时候也有下拉提示并且选择项目后,单价框显示单价. 用的是autocomplete插件

下面是代码:

<script src="http://apps.bdimg.com/libs/jquery/1.10.2/jquery.min.js"></script>
<link rel="stylesheet" href="http://apps.bdimg.com/libs/jqueryui/1.10.4/css/jquery-ui.min.css">
<script type="text/javascript" src="ui/jquery.ui.core.js"></script>
<script type="text/javascript" src="ui/jquery.ui.widget.js"></script>
<script type="text/javascript" src="ui/jquery.ui.position.js"></script>
<script type="text/javascript" src="ui/jquery.ui.autocomplete.js"></script>
</head>

<body>
<script>
$(function() {
var projects = [
{
value: "12",
label: "jQuery",
},
{
value: "21",
label: "jQuery UI",
},
{
value: "23",
label: "Sizzle JS",
}
];
$( "#objname" ).autocomplete({
minLength: 0,
source:projects,
focus: function( event, ui ) {
$( "#objname" ).val( ui.item.label );
return false;
},
select: function( event, ui ) {
$( "#objname" ).val( ui.item.label );
$( "#price" ).val( ui.item.value );
return false;
}
})
});

</script>
<table width="100%" border="0" cellpadding="0" cellspacing="0" id="optionContainer">
<TR class="title3">
<td class="td_l_c" width="60">序号</td>
<td class="td_l_c" width="200">项目</td>
<td class="td_l_c" width="80">单价</td>
<td class="td_l_c" width="100">次数</td>
<td class="td_l_c" width="100">金额</td>
<td class="td_l_c" width="60">折扣</td>
<td class="td_l_c" width="80">操作</td>
</TR>
<TR>
<td class="td_l_c"><input name="number" type="text" class="int" size="5" value="1" /></td>
<td class="td_l_c"><input name="objname" id="objname" type="text" class="int" size="30" placeholder="请输入项目名字或拼音" /></td>
<td class="td_l_c"><input name="price" id="price" type="text" class="int" size="10"/></td>
<td class="td_l_c"><input name="count" id="count" type="text" class="int" size="5" onkeyup="NumberCheck(this)"/></td>
<td class="td_l_c"><input name="money" id="money" type="text" class="int" size="12" readonly="readonly" value="0" /></td>
<td class="td_l_c"><input name="zhekou" id="zhekou" type="text" class="int" size="3" value="100"/>%</td>
<td class="td_l_c"><a href="#" onclick="addRow()">增加</a></td>
</TR>
</table>
<div style="width:99.9%; border-top:1px solid #E1E2E4; border-right:1px solid #E1E2E4; overflow:hidden;">
<li style="width:20%; float:right; line-height:32px;">总金额<input name="total" id="total" type="text" class="int" size="10" readonly="readonly" value="0" /></li>
<li style="width:15%; float:right; line-height:32px;">共计<input name="itemt" id="itemt" value="1" type="text" class="int" size="3" readonly="readonly" />个项目</li>
</div>
<script type="text/javascript">
//增加行
function addRow(){
var rowCount = $('#optionContainer tr').length;
var newRow='<tr>'
+'<td class="td_l_c"><input name="number" type="text" class="int" size="5" value="'+rowCount+'"></td>'
+'<td class="td_l_c"><input name="objname" type="text" class="int" size="30" placeholder="请输入项目名字或拼音" /></td>'
+'<td class="td_l_c"><input name="price" type="text" class="int" size="10" /></td>'
+'<td class="td_l_c"><input name="count" type="text" class="int" size="5" onkeyup="NumberCheck(this)"/></td>'
+'<td class="td_l_c"><input name="money" type="text" class="int" size="12" readonly="readonly" value="0" /></td>'
+'<td class="td_l_c"><input name="zhekou" type="text" class="int" size="3" value="100"/>%</td>'
+'<td class="td_l_c"><a href="#" onclick="delRow(this)">删除</a></td>'
+'</tr>';
$('#optionContainer').append(newRow);
$("#itemt").val(rowCount);
}
//删除行
function delRow(t){
$(t).closest("tr").remove();
$('#optionContainer input[name="number"]').val(function (i) {return i+1;});
var rowCount = $('#optionContainer tr').length-1;
$("#itemt").val(rowCount);
allmoney();
}
//计算金额
$(function(){
$("#optionContainer").on("keyup", 'input[name="price"],input[name="count"],input[name="zhekou"]', function(event){
var tr = $(this).closest("tr");
var e1 = $('input[name="price"]',tr).val() || 0;
var e2 = $('input[name="count"]',tr).val() || 0;
var e3 = $('input[name="zhekou"]',tr).val() || 0;
if(isNaN(e1)){e1=0;$('input[name="price"]',tr).val(0);}
if(isNaN(e2)){e2=0;$('input[name="count"]',tr).val(0);}
if(isNaN(e3)){e3=0;$('input[name="zhekou"]',tr).val(0);}
$('input[name="money"]',tr).val(parseFloat(e1)*parseInt(e2)*parseInt(e3)/100);
allmoney();
})
})
//显示总金额
function allmoney() {
var money = 0;
$('#optionContainer input[name="money"]').each(function () {
money += parseFloat($(this).val()) || 0;
});
$("#total").val(money);

}

function NumberCheck(t){ //数量输入框只能输入整数
var num = t.value;
var re=/^\d*$/;
if(!re.test(num)){
isNaN(parseInt(num))?t.value=0:t.value=parseInt(num);
}
}
</script>

...全文
142 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
Hello World, 2016-12-03
  • 打赏
  • 举报
回复
第一,用ID来访问只会返回第一个匹配的元素 第二,你新增加的行控件没有ID 第三,新增加的行没有添加autocomplete事件
weiba963 2016-12-03
  • 打赏
  • 举报
回复
没人么。没人么
第1章(\1) 示例描述:变量。 1_1.htm 变量声明。 1_2.htm 局部变量和全局变量。 1_3.htm JavaScript中的强制类型转换。 1_4.htm 在HTML中为JavaScript传递变量。 1_5.htm 在HTML中引用JavaScript的变量。 1_6.htm 比较undefined和"undefined"。 第2章(\2) 示例描述:客户端的流程控制。 2_1.htm 条件判断语句if…else 2_2.htm 多条件判断语句switch。 2_3.htm 嵌套循环语句for。 2_4.htm 循环语句while。 2_5.htm 控制循环过程break和continue。 2_6.htm 利用流程控制语句实现冒泡排序。 第3章(\3) 示例描述:字符串操作。 3_1.htm 连接字符串。 3_2.htm 在字符串中查找指定字符。 3_3.htm 提取字符串中的字串。 3_4.htm 替换字符串中的指定字符。 3_5.htm 将字符串分解为数组。 3_6.htm 字符串大小写的书写和判断。 第4章(\4) 示例描述:数组技术。 4_1.htm 创建空数组。 4_2.htm 创建带初始值的数组。 4_3.htm 将数组转换为字符串。 4_4.htm 遍历数组中的元素。 4_5.htm 合并两个数组。 4_6.htm 创建多维数组。 4_7.htm 数组排序。 第5章(\5) 示例描述:JavaScript快速处理日期时间的操作。 5_1.htm 获取当前日期并显示在HTML页中。 5_2.htm 分别获取当前时间的年月日时分秒。 5_3.htm 时间的水中倒影。 5_4.htm 简单的日历。 5_5.htm 标题栏显示日期。 5_6.htm 标题栏显示时间。 5_7.htm 不同时间的不同问候。 第6章(\6) 示例描述:JavaScript页面处理技巧。 6_1.htm 用JavaScript实现一个页面两份样式表。 6_2.htm 用JavaScript动态更换图像元素中的图像。 6_3.htm 利用搜索引擎引用来高亮页面关键字。 6_4.htm 使用匿名函数为定时器传递参数。 6_5.htm Web页面中的tooltip提示。 6_6.htm 在Web页面中控制其元素的选择状态。 第7章(\7) 示例描述:JavaScript的鼠标事件和键盘事件。 7_1.htm 按钮的鼠标单击事件。 7_2.htm 用鼠标点亮文本。 7_3.htm 渐显图片。 7_4.htm 跟随鼠标的图片。 7_5.htm 跟随鼠标的*。 7_6.htm 跟随鼠标的文字。 7_7.htm 判断Ctrl键是否被按下。 7_8.htm 设置页面中某按钮的热键。 第8章(\8) 示例描述:窗口大小自动化管理。 8_1.htm 按指定要求打开的窗口。 8_2.htm 控制窗口的打开和关闭。 8_3.htm 从天而降的窗口。 8_4.htm 打开慢慢变大的窗口。 8_5.htm 打开一个四面变大的窗口。 8_6.htm 页面左右分开。 8_7.htm 定时打开网页。 8_8.htm 自动打开新的窗口。 第9章(\9) 示例描述:JavaScript结合文字实现特殊页面。 9_1.htm 逐隐逐现的文字特效。 9_2.htm 超酷的文字特效。 9_3.htm 阴影文字的特殊效果。 9_4.htm 彩色文字的特殊效果。 9_5.htm 升降文字的特殊效果。 9_6.htm 打字效果的文字特效。 9_7.htm 淡入淡出的文字效果。 9_8.htm 炽热文字的特殊效果。 第10章(\10) 示例描述:页面中的链接地址个性化。 10_1.htm 按时消失的链接。 10_2.htm 带滚动提示的链接。 10_3.htm 动态变换的链接。 10_4.htm 滚动链接。 10_5.htm 不断闪动的链接。 10_6.htm 在按钮上显示不同的链接。 10_7.htm 带链接的滚动字幕。 第11章(\11) 示例描述:在HTML中用JavaScript控制图像页面。 11_1.htm 不停闪烁的图片。 11_2.htm 图片展示选项。 11_3.htm 图片的渐显播放。 11_4.htm 将图片固定在页面左上角。 11_5.htm 左右移动的图片。 11_6.htm 图像滚动公告版。 11_7.

87,915

社区成员

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

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