文本框追加赋值 大侠们好,问题是这样的:前端商品列表显示 显示的规则就是 商品名称前面有一个单选框,选择单选的商品点击确定按钮将选择的商品名称赋值给后面的文本框,目前这个功能已经实现,现在就是希望追加显示。追加显示就是再次选择并且确认文本框中就以逗号隔开 追加显示商品名称,如: 【a商品,b商品,...】因为对jquery不是很熟,搜了半天没解决 求大侠帮忙! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 $("#qSchoolName").val($("#qSchoolName").val()+'aa'); <script src="http://www.coding123.net/js/jquery.js" type="text/javascript"></script><script type="text/javascript"> $(function () { var txt = $('#txt')[0]; $('input:checkbox').click(function () { if (this.checked) txt.value += ',' + this.nextSibling.data; else txt.value = txt.value.replace(',' + this.nextSibling.data, ''); }); });</script><div><input type="checkbox" />商品1</div><div><input type="checkbox" />商品2</div><div><input type="checkbox" />商品3</div><div><input type="checkbox" />商品4</div><div><input type="checkbox" />商品5</div><input type="text" style="width:100%" id="txt"> <script src="http://www.coding123.net/js/jquery.js" type="text/javascript"></script> <script type="text/javascript"> $(function () { $("#btnConfirm").bind("click", function () { $("#txt").val(""); var txtValue = ""; $("input[type='checkbox']:checked").each(function () { var text = $.trim($(this).parent("div").text()); if (txtValue.indexOf(text) == -1) { if (txtValue == "") txtValue = text; else { txtValue += "," + text; } } }); $("#txt").val(txtValue); }); }) </script> <div> <input type="checkbox" />商品1 </div> <div> <input type="checkbox" />商品2 </div> <div> <input type="checkbox" />商品3 </div> <div> <input type="checkbox" />商品4 </div> <div> <input type="checkbox" />商品5 </div> <input type="button" id="btnConfirm" value="confirm" /> <input type="text" style="width: 100%" id="txt"> jquery 百度下拉模糊查询效果 关于判断字符串 js 运行某段代码N次 js 创建表格 一个测试网页的工具是jar文件,调用后IE打不开网页,出现"400 Bad Request Bad filename"错误 请教大家一个正则的问题,谢谢 单元格rows,cells的问题 请问在同一页面里能使用多个 javascript 吗? 大家来帮我看看这个代码 为什么窗口关闭了还在运行后面的代码?我想窗口关闭就不再运行后面的代码,怎么办? 谁能帮修改兼容所有浏览器 web开发 如何防止重复提交
<script src="http://www.coding123.net/js/jquery.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
var txt = $('#txt')[0];
$('input:checkbox').click(function () {
if (this.checked) txt.value += ',' + this.nextSibling.data;
else txt.value = txt.value.replace(',' + this.nextSibling.data, '');
});
});
</script>
<div><input type="checkbox" />商品1</div>
<div><input type="checkbox" />商品2</div>
<div><input type="checkbox" />商品3</div>
<div><input type="checkbox" />商品4</div>
<div><input type="checkbox" />商品5</div>
<input type="text" style="width:100%" id="txt">
<script src="http://www.coding123.net/js/jquery.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$("#btnConfirm").bind("click", function () {
$("#txt").val("");
var txtValue = "";
$("input[type='checkbox']:checked").each(function () {
var text = $.trim($(this).parent("div").text());
if (txtValue.indexOf(text) == -1) {
if (txtValue == "")
txtValue = text;
else {
txtValue += "," + text;
}
}
});
$("#txt").val(txtValue);
});
})
</script>
<div>
<input type="checkbox" />商品1
</div>
<div>
<input type="checkbox" />商品2
</div>
<div>
<input type="checkbox" />商品3
</div>
<div>
<input type="checkbox" />商品4
</div>
<div>
<input type="checkbox" />商品5
</div> <input type="button" id="btnConfirm" value="confirm" />
<input type="text" style="width: 100%" id="txt">