<!DOCTYPE html>
<html>
<head>
<meta charset="utf8">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<script type="text/javascript">
$(function (){
$("input[type=radio]").each(function(){
console.debug($(this).val());
});
$("input[type=text]").each(function(){
$(this).val("C.Y. Fang") ;
});
});
function MyClean(){
$("input[type=radio]:checked").each(function(){
$(this).prop("checked", false)
});
$("input[type=text]").each(function(){
$(this).val('') ;
});
}
</script>
</head>
<body>
<div>
<input type="radio" value="男">男
<input type="radio" value="女">女
<input type="text">
</div>
<button onclick="MyClean()">Clean</button>
</body>
</html>
參考資料:
https://api.jquery.com/jQuery.each/
http://stackoverflow.com/questions/18659726/jquery-find-all-the-visible-required-fields
http://stackoverflow.com/questions/1280499/jquery-set-select-index
http://stackoverflow.com/questions/3165413/how-to-get-input-type-using-jquery
http://stackoverflow.com/questions/306583/this-selector-and-children
http://stackoverflow.com/questions/4088467/get-value-in-input-text-box