我做了这个jsfiddle:http: //jsfiddle.net/6tZmc/1/
基本上,我想根据单选按钮选择更新一个空跨度。这是代码:
html
<div>
<p>Your chose: <span id="animal"></span></p>
</div>
<div>
<h2>Pick an Animal:</h2>
<input type="radio" name="pets" value="cat" />Cats<br />
<input type="radio" name="pets" value="dog" />Dogs
</div>
jQuery :
function petChoice(){
var chosenPet = $('input[name="pets"]:checked').val();
if(chosenPet = 'cat'){
$("span#animal").text();
$("span#animal").text("Cats");
}else if (chosenPet = 'dog'){
$("span#animal").text();
$("span#animal").text("Dogs");
}else{
$("span#animal").text();
}
}
$("input[name='pets']").click(function(){
petChoice();
});
提前致谢