如題所說。 我想在 "group1currency1" 裡輸入一個數據 比如USD,然後點擊下面的按鈕,將"group1currency1"裡的內容復制到”outputcurrency1“。 下面是我的代碼,我嘗試了很多次都不成功, 希望有人能幫助我
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<p> Exchange Rates</P>
<table border="1">
<tr>
<th> </th>
<th>Currency #1</th>
<th>Currency #2</th>
<th>Bid</th>
<th>Ask</th>
</tr>
<tr>
<td><p>Group 1</td>
<td><input type="text" id="group1currency1"size="12" value=""></td>
</tr>
<tr>
<td><p>Group 1</td>
<td><input type="text" id="group2currency1"size="12" value=""></td>
</tr>
<tr>
<td><p>Group 3</td>
<td><span id="outputcurrency1"></td>
</tr>
</table>
<button type="button" id="outputbutton" class="btn btn-success">Output</button>
</div>
<!-- jQuery -->
<script src="js/exchange.js"></script>
</script>
</body>
</html>
這個是我在js文檔裡的代碼
var x= function(){
$("outputbutton").click(function(){
var str=document.getElementById("group1currency1").value;
document.getElementById("outputcurrency1").value = str;
});
};
id選擇器也搞錯了。。span標簽也沒有閉合,亂用屬性。。申明的方法也沒有執行綁定事件
jquery框架也未導入
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<p> Exchange Rates</p>
<table border="1">
<tr>
<th> </th>
<th>Currency #1</th>
<th>Currency #2</th>
<th>Bid</th>
<th>Ask</th>
</tr>
<tr>
<td><p>Group 1</td>
<td><input type="text" id="group1currency1" size="12" value=""></td>
</tr>
<tr>
<td><p>Group 1</td>
<td><input type="text" id="group2currency1" size="12" value=""></td>
</tr>
<tr>
<td><p>Group 3</td>
<td><span id="outputcurrency1"></span></td>
</tr>
</table>
<button type="button" id="outputbutton" class="btn btn-success">Output</button>
</div>
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.4.1.min.js"></script>
<script >
var x = function () {
$("#outputbutton").click(function () {/////////
var str = document.getElementById("group1currency1").value;
document.getElementById("outputcurrency1").innerHTML = str;///////////
});
};
x()///////////
</script>
</body>
</html>