我的jQuery代码如下所述。
$('.meraCheck').click(function () {
var text1 = "";
$('.meraCheck:checked').each(function () {
text1 += $(this).parent().text() + ',';
});
text1 = text1.substring(0, text1.length - 1);
$('#selectedConsiderationsText').val(text1);
var pane = $('#selectedConsiderationsText');
var trimmed_text= pane.val($.trim(pane.val()).replace(/\s*[\r\n]+\s*/g, '\n').replace(/(<[^\/][^>]*>)\s*/g, '$1').replace(/\s*(<\/[^>]+>)/g, '$1'));
});
$('.meraRadio').click(function () {
var text = "";
$('.meraRadio:checked').each(function () {
text += $(this).parent().text() + ',';
});
text = text.substring(0, text.length - 1);
$('#selectedConsiderationsText').val(text);
var pane = $('#selectedConsiderationsText');
pane.val($.trim(pane.val()).replace(/\s*[\r\n]+\s*/g, '\n').replace(/(<[^\/][^>]*>)\s*/g, '$1').replace(/\s*(<\/[^>]+>)/g, '$1'));
});
目前在文本区域中,它反映了如下所述的文字:
我想要的是我想合并选定的checbox和单选按钮的值(同时) 在那个textarea。
可以请任何人协助我如何做到这一点吗?
Checbkox,Radiobutton和Text区域的代码在这里:
<input isselected="True" checked="checked" class="meraCheck" type="checkbox" value="12389" style="transform: scale(1);">
<input class="meraRadio" style="transform: scale(1);margin-left: 25px;" type="radio" value="11100">
<textarea rows="4" cols="50" id="selectedConsiderationsText"></textarea>
答案 0 :(得分:1)
检查以下答案!
$(function() {
$('.meraCheck, .meraRadio').click(function() {
var text1 = "";
$('.meraCheck:checked').each(function() {
text1 += $(this).val() + ',';
});
$('.meraRadio:checked').each(function() {
text1 += $(this).val() + ',';
});
text1 = text1.substring(0, text1.length - 1);
$('#selectedConsiderationsText').val(text1);
var pane = $('#selectedConsiderationsText');
var trimmed_text = pane.val($.trim(pane.val()).replace(/\s*[\r\n]+\s*/g, '\n').replace(/(<[^\/][^>]*>)\s*/g, '$1').replace(/\s*(<\/[^>]+>)/g, '$1'));
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input isselected="True" name="meraCheck" class="meraCheck" type="checkbox" value="12389" style="transform: scale(1);">12389
<input isselected="True" name="meraCheck" class="meraCheck" type="checkbox" value="12390" style="transform: scale(1);">12390
<input class="meraRadio" name="meraRadio" style="transform: scale(1);margin-left: 25px;" type="radio" value="11100">11100
<input class="meraRadio" name="meraRadio" style="transform: scale(1);margin-left: 25px;" type="radio" value="11101">11101
<textarea rows="4" cols="50" id="selectedConsiderationsText"></textarea>
答案 1 :(得分:0)
请看一下这种方法:
$(document).ready(function() {
$('.meraCheck').click(function() {
updateText();
});
$('.meraRadio').click(function() {
updateText();
});
function updateText() {
var text = "";
$('.meraRadio:checked').each(function() {
text += $(this).parent().text() + ',';
});
$('.meraCheck:checked').each(function() {
text += $(this).parent().text() + ',';
});
text = text.substring(0, text.length - 1);
$('#selectedConsiderationsText').val(text);
var pane = $('#selectedConsiderationsText');
var trimmed_text = pane.val($.trim(pane.val()).replace(/\s*[\r\n]+\s*/g, '\n').replace(/(<[^\/][^>]*>)\s*/g, '$1').replace(/\s*(<\/[^>]+>)/g, '$1'));
}
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<div>My CheckBox
<input isselected="True" class="meraCheck" type="checkbox" value="12389" style="transform: scale(1);">
</div>
<div>My RadioBox
<input class="meraRadio" style="transform: scale(1);margin-left: 25px;" type="radio" value="11100">
</div>
<textarea rows="4" cols="50" id="selectedConsiderationsText"></textarea>
&#13;