Javascript 将表行转换为输入
我有两个表格,每一行表格都有一个复选框Javascript 将表行转换为输入,javascript,jquery,Javascript,Jquery,我有两个表格,每一行表格都有一个复选框 <table class="One"> <thead> <tr> <th>choose</th> <th>Code 1</th> </tr> </thead> <tbody> <tr> <th scope="row"><input type="checkbox"
<table class="One">
<thead>
<tr>
<th>choose</th>
<th>Code 1</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row"><input type="checkbox" class="form-check-input"></th>
<td>123</td>
</tr>
选择
代码1
123
选择
代码2
456789
模态内部有一个形式
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#formModal">
Continue
</button>
<div class="modal fade" id="formModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Modal Form</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form action="" method="post">
/* inputs here */
<button type="submit" class="btn btn-primary">Submit</button>
</form>
</div>
</div>
</div>
</div>
继续
情态形式
&时代;
/*此处输入*/
提交
我只想从每个表中捕获一个复选框,并在单击“继续”按钮“模式”时转换为模式内的输入。如何使用jquery实现这一点
编辑
我可以将这些值传递给变量jquery。
如何获取此值并使用它在模式中创建输入?
$(文档)。在('click','btn_Continue',函数()上{
var-inpId=0;
$('#dvInputs').html('');
$('table.One input[type=checkbox]:checked')。每个(函数(){
var chkValue=$(this.closest('th').next('td').text();
$('#dvInputs')。追加($('');
inpId++;
});
$('table.Two input[type=checkbox]:checked')。每个(函数(){
var chkValue=$(this.closest('th').next('td').text();
$('#dvInputs')。追加($('');
inpId++;
});
返回false;
});代码>
选择
代码1
123 A
123 B
选择
代码2
456789 A
456789 B
继续
情态形式
&时代;
提交
$(文档)。在('click','btn_Continue',函数()上{
var-inpId=0;
$('#dvInputs').html('');
$('table.One input[type=checkbox]:checked')。每个(函数(){
var chkValue=$(this.closest('th').next('td').text();
$('#dvInputs')。追加($('');
inpId++;
});
$('table.Two input[type=checkbox]:checked')。每个(函数(){
var chkValue=$(this.closest('th').next('td').text();
$('#dvInputs')。追加($('');
inpId++;
});
返回false;
});代码>
选择
代码1
123 A
123 B
选择
代码2
456789 A
456789 B
继续
情态形式
&时代;
提交
看看另一个版本,它将循环所有包含选中复选框的表,这只是一个示例,选择器可以更具体一些
$(function() {
$('.btn-primary').on('click', function(){
$('form').find('p').empty();
$('table').each(function(){
var $this = $(this);
var $checkBox = $this.find('input[type="checkbox"]');
if ($checkBox.prop('checked')){
$('form').find('p').append($checkBox.parent().next().html());
}
});
})
});
看看另一个版本,它将循环所有包含选中复选框的表,这只是一个示例,选择器可以更具体一些
$(function() {
$('.btn-primary').on('click', function(){
$('form').find('p').empty();
$('table').each(function(){
var $this = $(this);
var $checkBox = $this.find('input[type="checkbox"]');
if ($checkBox.prop('checked')){
$('form').find('p').append($checkBox.parent().next().html());
}
});
})
});
将name属性添加到复选框中
<input type="checkbox" class="form-check-input" name="first">
将类添加到模态表单中-
<form class="s" action="" method="post">
$( "#formModal" ).on('shown', function(){
var wrapper = $(".s"); //Fields wrapper
$(wrapper).prepend('<input type="text" id="forcode1" /><input type="text" id="forcode2" />'); //add input box
});
$(“#formModal”).on('显示',函数(){
var wrapper=$(“.s”);//字段包装器
$(包装器).prepend(“”);//添加输入框
});
将name属性添加到复选框中
<input type="checkbox" class="form-check-input" name="first">
将类添加到模态表单中-
<form class="s" action="" method="post">
$( "#formModal" ).on('shown', function(){
var wrapper = $(".s"); //Fields wrapper
$(wrapper).prepend('<input type="text" id="forcode1" /><input type="text" id="forcode2" />'); //add input box
});
$(“#formModal”).on('显示',函数(){
var wrapper=$(“.s”);//字段包装器
$(包装器).prepend(“”);//添加输入框
});
在按钮上单击模态弹出,读取选中的值并将其显示在屏幕上modal@Se0ng11是的,我想了解一下,当点击模态按钮时,输入是以模态内的形式创建的。您需要显示一些代码,无论是否工作,您实际做了什么,或者我们可以使用一些JSFIDLE,这样我们就可以在issue@Se0ng11我在问题中添加了JSFIDLE,但这不是一个解决方案,因为当您取消选中复选框时,它将类似于再次单击按钮,再次激活值,而不是在按钮单击模式弹出时清除变量,读取选中的值并将其显示在屏幕上modal@Se0ng11是的,我想了解一下,当点击模态按钮时,输入是以模态内的形式创建的。您需要显示一些代码,不管是否工作,您实际做了什么,或者我们可以使用的一些JSFIDLE,这样我们就可以在issue@Se0ng11我在我的问题中添加了JSFIDLE,但这不是一个解决方案,因为当您取消选中复选框时,它将类似于再次单击按钮,再次激活值,而不是清除变量希望您需要类似的内容。如果有任何更改,请明确说明。请帮助我回答有关选择器的问题。对不起,我看到此消息有点晚。不管怎样,希望你能得到这个问题的答案。希望你需要像这样的东西。如果有任何更改,请明确说明。请帮助我回答有关选择器的问题。对不起,我看到此消息有点晚。不管怎样,希望你能得到这个问题的答案。