这是我从检查字段中获取价值的代码..
$(document).ready(function(){
$(document).on("change keyup mouseup", "#title", function(){
$("#alias").val($("#title").val())
});
});
https://jsfiddle.net/javasalden/vf4uzjhp/
如何完成此代码以显示:
产出:丰田,本田,奥迪
产出:丰田,奥迪
答案 0 :(得分:2)
检查以下代码。您需要获取所有checked
并在输入字段中附加值:
var checkboxes = $(".has-value");
checkboxes.on("change", function() {
$("#alias").val(
checkboxes.filter(":checked").map(function() {
return this.value;
}).get().join(", ")
);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input class="has-value m-r" id="title" value="Toyota," type="checkbox">Toyota
<input class="has-value m-r" value="Honda," type="checkbox">Honda
<input class="has-value m-r" value="Honda," type="checkbox">Audi
<br><br>
<input class=" " name="alias" id="alias">
<br><br> if i check "HONDA" and "AUDI"<br><br> result input will like this Toyota, Honda, Audi
<br><br><br> if i Uncheck Honda
<br><br> result will like this Toyota, Audi
答案 1 :(得分:0)
应该做的伎俩。
<input class="has-value m-r" id="title" value="Toyota" type="checkbox">Toyota
<input class="has-value m-r" value="Honda" type="checkbox">Honda
<input class="has-value m-r" value="Audi" type="checkbox">Audi
<br><br>
<input class=" " name="alias" id="alias" >
<br><br>
if i check "HONDA" and "AUDI"<br><br>
result input will like this Toyota, Honda, Audi
<br><br><br>
if i Uncheck Honda
<br><br>
result will like this Toyota, Audi
$(document).ready(function(){
$('.has-value').click(function() {
var t = "";
$('.has-value:checked').each(function() {
if( t== "") {
t = $(this).val();
}
else {
t = t + ","+ $(this).val();
}
});
$('#alias').val(t);
})
});