Example application of val of in jQuery
- 2020-03-30 02:09:03
- OfStack
1, example source code
2. The results are as follows
(1) select all
"Basketball, football and volleyball"
(2) select part
The corresponding values pop up in turn
(3) not at all
Don't play window
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>jQuery In the val()</title>
<script type="text/javascript" src="jquery-2.1.0.js"></script>
<script type="text/javascript">
$(function(){
$("#btn").click(function(){
$("input[name=ckb]:checked").each(function() {
alert($(this).val());
});
});
});
</script>
</head>
<body>
<div id="div1">
<table>
<tr>
<td>
<input type="checkbox" id="ckb1" name="ckb" value=" basketball "/> basketball
<input type="checkbox" id="ckb2" name="ckb" value=" football "/> football
<input type="checkbox" id="ckb3" name="ckb" value=" volleyball "/> volleyball
</td>
</tr>
<tr>
<td>
<input type="button" id="btn" value=" The values "/>
</td>
</tr>
</table>
</div>
</body>
</html>
2. The results are as follows
(1) select all
"Basketball, football and volleyball"
(2) select part
The corresponding values pop up in turn
(3) not at all
Don't play window