Skip to content

Instantly share code, notes, and snippets.

@roseforyou
Created January 3, 2014 04:51
Show Gist options
  • Save roseforyou/8232935 to your computer and use it in GitHub Desktop.
Save roseforyou/8232935 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
<a id="_js_checkAll" href="#">全选</a>&nbsp;<a id="_js_cancelAll" href="#">取消全选</a><br>
<input type="checkbox" name="vehicle" value="address">Address<br>
<input type="checkbox" name="vehicle" value="call">Call history <br>
<input type="checkbox" name="vehicle" value="sms">SMS <br>
<input type="checkbox" name="vehicle" value="mail">Mail <br>
<span class="_js_span"><input type="radio" name="vehicle2" value="all">all backup</span><br>
<span class="_js_span"><input type="radio" name="vehicle2" checked="true" value="pc">only pc</span><br>
<span>Checkbox value:</span><span id="_js_cbxVal"></span><br>
<span>Raido value:</span><span id="_js_rdoVal"></span><br>
<input type="button" id="_js_btn" value="cal">
<script>
var $checkBox = $('input[type="checkbox"]');
var $radio = $('._js_span');
$('#_js_checkAll').on('click', function(e){
e.preventDefault();
$checkBox.attr('checked', true);
});
$('#_js_cancelAll').on('click', function(e){
e.preventDefault();
$checkBox.attr('checked', false);
});
$radio.on('click', function(){
$(this).find('input').attr('checked', true);
});
$('#_js_btn').on('click', function(){
var $cbxval = $('#_js_cbxVal');
$cbxval.html('');
$('input[type="checkbox"]:checked').each(function(){
$cbxval.html(($cbxval.html()==''?$cbxval.html():$cbxval.html()+',')+$(this).val());
});
$('#_js_rdoVal').html($('input[type="radio"]:checked').val());
});
</script>
<!--
</body>
</html>-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment