我尝试了这段代码。我的问题是如何将文本值传输到持有者,每个输入应该用逗号分隔,并且不应重复输入值任何人都可以帮助我提前谢谢您。
<input type="text" name="text" id="text">
<button type="button" id="button"> Button </button>
<Br> <Br>
<input type="holder" id="holder" name="holder">
<script>
$(document).ready(function() {
$("#button").click(function() {
$('#text').each(function() {
if ($(this).val() == $current.val() && $(this).attr('id') != $current.attr('id'))
{
alert('duplicate found!');
}
var data = [];
$.each($("#text"), function() {
data.push($(this).attr("value"));
});
$('#holder').val(data.join(","));;
});
});
</script>
最佳答案
试试这个..
$("#button").click(function() {
$text = $('#text');
$textval = $text.val();
$holder = $('#holder');
$holderval = $holder.val();
if ($holderval.trim().length) {
var duplicate;
duplicate = $holderval.split(',').filter(function(hv) {
return hv == $textval;
})
if (duplicate.length) {
alert("Duplicate found");
return false;
}
$holder.val($holderval += ',' + $textval);
} else {
$holder.val($holderval += $textval);
}
$text.val('');
});
$("#button").click(function() {
$text = $('#text');
$textval = $text.val();
$holder = $('#holder');
$holderval = $holder.val();
if ($holderval.trim().length) {
var duplicate;
duplicate = $holderval.split(',').filter(function(hv) {
return hv == $textval;
})
if (duplicate.length) {
alert("Duplicate found");
return false;
}
$holder.val($holderval += ',' + $textval);
} else {
$holder.val($holderval += $textval);
}
$text.val('');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" name="text" id="text">
<button type="button" id="button">Button</button>
<Br>
<Br>
<input type="holder" id="holder" name="holder">
关于jquery - 如何将 textbox1 的值传输到 textbox2 中,每个输入以逗号分隔,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38788626/