<html>
<head>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<script src="http://code.jquery.com/jquery-1.8.0.min.js"></script>
<script>
function radioTest() {
var ret;
for(var i = 0; i < 3; i++) {
if($('#r-'+i).attr('checked')) {
ret = i;
break;
}
}
console.log(ret);
if(ret) {
console.log(ret+" has been selected.");
return ret;
} else {
alert("No item is selected.");
}
}
function checkBoxTest() {
var arr = new Array();
for(var i = 0; i < 3; i++) {
if ($('#c-'+i).attr('checked')) {
alert("#c-"+i+" is selected!" + '---');
arr.push($('#c-'+i).val());
} else {
alert("#c-"+i+" is unselected!");
}
}
console.log(arr);
}
</script>
</head>
</head>
<body>
<p>本例演示 If 语句。</p>
<p>如果浏览器时间小于 10,那么会向您问“早安”。</p>
<input type="checkbox" name="c-0" id="c-0" value="0">fdsf1
<input type="checkbox" name="c-1" id="c-1" value="1">fdsf2
<input type="checkbox" name="c-2" id="c-2" value="2">fdsf3
</br>
<input type="radio" name="r" id="r-0" value="0">fdsf1
<input type="radio" name="r" id="r-1" value="1">fdsf2
<input type="radio" name="r" id="r-2" value="2">fdsf3
</br>
<input type="button" onclick="radioTest()" value="radio">
<input type="button" onclick="checkBoxTest()" value="checkBox">
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<script src="/jquery/jquery-1.11.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$(".ex .hide1").click(function(){
$(this).parents(".ex").hide("slow");
});
});
</script>
<style type="text/css">
div.ex
{
background-color:#e5eecc;
padding:7px;
border:solid 1px #c3c3c3;
}
</style>
</head>
<body>
<h3>中国办事处</h3>
<div class="ex">
<button class="hide1" type="button">隐藏</button>
<p>联系人:张先生<br />
北三环中路 100 号<br />
北京</p>
</div>
<h3>美国办事处</h3>
<div class="ex">
<button class="hide1" type="button">隐藏</button>
<p>联系人:David<br />
第五大街 200 号<br />
纽约</p>
</div>
</body>
</html>