如何使用jquery创建动态复选框 [英] how to create dynamic checkbox using jquery
问题描述
如何使用jquery创建动态复选框
1.生成.....
文本框生成然后在所有生成的附加复选框文本框
2.计算...
生成6个文本框和chk框并填写值在所有文本框但复选框只检查3文本框然后总和按钮单击计算仅检查文本框值并显示总计...
please帮助我....
我的文本框生成代码并使用不使用Checkbox计算值..
--------------------------------代码--------- -------------------------------
how to create dynamic checkbox using jquery
1. Generate .....
Textbox generate then attach checkbox in all generated textbox
2. Calculation...
Total 6 textbox and chk box generated and fill the value in all textbox but checkbox check only 3 textbox then sum button click calculate only checked textbox value and display in total ...
please help me ....
my textbox generated code and Calculate value using without Checkbox ..
--------------------------------Code----------------------------------------
<script>
$(document).ready(function ()
{
$("#btnshow").click(function ()
{
var rows = $("#txtRows").val();
var columns = $("#txtColumns").val();
var htmlData = "";
for (var i = 0; i < rows; i++)
{
//var $ctr = $('<input/>').attr({ type: 'checkbox', name: 'chk' }).addClass("chk");
//$("#tblGnrate").append($ctrl);
htmlData += "<tr>";
for (var j = 0; j < columns; j++)
{
htmlData += "<td><input type='text' name='txtValue' id='txtBox" + i + "" + j + "' /></td>"
}
htmlData += "</tr>";
}
$("#tblGnrate").html(htmlData);
});
// sum all the text box values
var Total = 0;
$("#btnsum").click(function ()
{
$('#tblGnrate').each(function (i, row)
{
var $row = $(row), $txtbox = $row.find('input[name="txtValue"]');
$txtbox.each(function (i, txtbox)
{
var $t = $(txtbox);
Total = Total + parseInt($t.val(),10);
});
});
alert(Total);
Total = 0;
});
});
</script>
</head>
<body>
Rows:<input type="text" id="txtRows" />
Columns:<input type="text" id="txtColumns" /><br /><br /><br />
<input type="button" id="btnshow" value="Generate" />
<input type="button" id="btnsum" value="Calculate" />
<table id="tblGnrate"></table>
---------------- ---------------------------------
请提供文本框和复选框代码和总和值仅选中textbox
-------------------------------------------------
please provide textbox and checkbox code and sum value only checked textbox
推荐答案
(文件).ready(function()
{
(document).ready(function () {
(#btnshow)。click(function()
{
var rows =
("#btnshow").click(function () { var rows =
(#txtRows ).val();
var columns =
("#txtRows").val(); var columns =
这篇关于如何使用jquery创建动态复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!