将复选框值放入类似内容的div中 [英] Get checkbox value into a div like content
本文介绍了将复选框值放入类似内容的div中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在这里找到了此代码...除了在警报中显示这些值之外,如何在div等文本内容上显示它们?
I found this code here... Instead of displaying the values on an alert, how to show them on a div like text content?
<script type="text/javascript" src="http://code.jquery.com/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("button").click(function(){
var favorite = [];
$.each($("input[name='sport']:checked"), function(){
favorite.push($(this).val());
});
alert("My favourite sports are: " + favorite.join(", "));
});
});
我想在div上显示"checkboxvalues"上的值,我该怎么做?
I want to show the values on the div "checkboxvalues", how do i do that?
<div id="checkboxvalues"></div>
<form>
<h3>Select your favorite sports:</h3>
<label><input type="checkbox" value="football" name="sport"> Football</label>
<label><input type="checkbox" value="baseball" name="sport"> Baseball</label>
<label><input type="checkbox" value="cricket" name="sport"> Cricket</label>
<label><input type="checkbox" value="boxing" name="sport"> Boxing</label>
<label><input type="checkbox" value="racing" name="sport"> Racing</label>
<label><input type="checkbox" value="swimming" name="sport"> Swimming</label>
<br>
<button type="button">Get Values</button>
</form>
推荐答案
$("#checkboxvalues").html('My favourite sports are: ' + favorite.join(", "));
这篇关于将复选框值放入类似内容的div中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文