0
答えはラジオボタンで、一連の質問にはそれぞれの回答がid = creditamountのhtmlで更新されます。変数creditAmount私のコードは、2番目のラジオボタンをクリックした後でのみ機能しますか?何が起こっているのか?Jquery:ラジオボタンが初めてクリックされたときのラジオボタンのonclick機能
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="jquery-1.4.2.js"></script>
<link rel = "stylesheet" type="text/css" href="custom.css" />
<script>
var creditAmount;
$(document).ready(function(){
$("input[name='alive']").live('click', function(){
$("input").click(function() {
creditAnswer = $(":checked").val();
if (creditAnswer == "Yes")
{
creditAmount = 1000;
}
else if (creditAnswer == "No")
{
creditAmount = 100;
}
else if (creditAnswer == "Both")
{
creditAmount = 5000;
}
$("#creditamount").html(creditAmount);
});
});
});
</script>
</head>
<form>
<div id="creditlimit"> Credit Limit: </div><div id ="creditamount">0 </div>
Are you currently alive?
<input type="radio" name="alive" value="Yes" /> Yes
<input type="radio" name="alive" value="No" /> No
<input type="radio" name="alive" value="Both" /> Depends upon the day of the week.
</form>
</html>
を試してみてください。ありがとう。 – ponzicoder