第一個js +html程式
阿新 • • 發佈:2018-11-19
<script type="text/javascript">
var result_1;
var result_2;
function get()
{
var a = getFirstNumber();
var b = getTwiceNumber();
sendResult(a,b);
}
//給p標籤傳值
function sendResult(result_1,result_2)
{
var num = document.getElementById("result")
num.innerHTML ="input1="+ result_1+" "+"input2="+result_2;
}
//獲取第一位數字
function getFirstNumber()
{
var firstNumber = document.getElementById("first").value;
return firstNumber;
}
//獲取第二位數字
function getTwiceNumber()
{
var twiceNumber = document.getElementById("twice").value;
return twiceNumber;
}
</script>
<p>@ [email protected]</p>
<table border="1" style="position:center;">
<tr>
<td>input1:</td>
<td><input type="text" id="first"/></td>
<td>input2:</td>
<td><input type="text" id="twice"/></td>
<td colspan="2" >
<button style="width:inherit" onclick="get()">get</button>
</td>
</tr>
<tr>
<td colspan="4" rowspan="4">
<p id="result"></p>
</td>
</tr>
</table>
var result_1;
var result_2;
function get()
{
var a = getFirstNumber();
var b = getTwiceNumber();
sendResult(a,b);
}
//給p標籤傳值
function sendResult(result_1,result_2)
{
var num = document.getElementById("result")
num.innerHTML ="input1="+ result_1+" "+"input2="+result_2;
}
//獲取第一位數字
function getFirstNumber()
{
var firstNumber = document.getElementById("first").value;
return firstNumber;
}
//獲取第二位數字
function getTwiceNumber()
{
var twiceNumber = document.getElementById("twice").value;
return twiceNumber;
}
</script>
<p>@
<table border="1" style="position:center;">
<tr>
<td>input1:</td>
<td><input type="text" id="first"/></td>
<td>input2:</td>
<td><input type="text" id="twice"/></td>
<td colspan="2" >
<button style="width:inherit" onclick="get()">get</button>
</td>
</tr>
<tr>
<td colspan="4" rowspan="4">
<p id="result"></p>
</td>
</tr>
</table>