0
有一些問題這段代碼的正確選擇,我想更換一塊的HTML代碼定義背景是在從單選按鈕選項中選擇一個的選擇是什麼。我似乎無法得到正確的選擇。無法獲取.replaceWith方法
<html>
<head>
<title>Javascript</title>
<link rel="stylesheet" type="text/css" href="stylesheet.css" />
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('#getValue').click(function(){
var input = $('input[name=choice]:checked').val();
});
if(input = 1)
{
$('#background').replaceWith('<img src="image source 1" alt="Background should be displayed here">');
}
if(input = 2)
{
$('#background').replaceWith('<img src="image source 2" alt="Background should be displayed here">');
}
if(input = 3)
{
$('#background').replaceWith('<img src="image source 3" alt="Background should be displayed here">');
}
});
</script>
</head>
<body id="body">
<div id="background">
<img src="image source 1" alt="Background should be displayed here">
</div>
<div id="footer">
<input type="radio" name="choice" value="1" />Scheme A
<input type="radio" name="choice" value="2" />Scheme B
<input type="radio" name="choice" value="3" />Scheme C
<input type="button" id="getValue" value="SELECT SCHEME"/>
</div>
</body>
</html>
另一種選擇是使用['.html'(HTTP: //api.jquery.com/html/)而不是'replaceInner':'$('#background')。html('...');' –