![](/img/trans.png)
[英]Is there something wrong with this call to a javascript function in an html form
[英]html onclick javascript function call to show something
我想調用 gettotal 函數從文本框和 * 3 中獲取值並將結果顯示在其他文本框中,代碼不起作用問題出在哪里!?
<html>
<head>
<script type="text/javascript" language="javascript">
function gettotal()
{
var x=0;
x=document.getElementById("pop").value*3;
document.getElementById("pop1").innerHTML="<b>"+x+"</b>";
}
</script>
<title>hello</title>
</head>
<body>
<form name="form1">
<input type="button" id="btn" name="btn" value="get" OnClick="gettotal()"/>
<input type="text" id="pop" name="pop" size="3"/>
<br/>
<br/>
<input type="text" id="pop1" name="pop1" size="5" value="val"/>
</form>
</body>
</html>
<html>
<head>
<script type="text/javascript" language="javascript">
function gettotal()
{
var x=0;
x=document.getElementById("pop").value*3;
document.getElementById("pop1").value=x;
}
</script>
<title>hello</title>
</head>
<body>
<form name="form1">
<input type="button" id="btn" name="btn" value="get" OnClick="gettotal()"/>
<input type="text" id="pop" name="pop" size="3"/>
<br/>
<br/>
<input type="text" id="pop1" name="pop1" size="5" value="val"/>
</form>
</body>
</html>
而不是.innerHTML() (用於將 HTML 標簽分配給元素)使用.value
將值分配給他的回答中提到的@Azzi 之類的輸入字段:
function gettotal() { var x=0; x=document.getElementById("pop").value*3; document.getElementById("pop1").value=x; }
<form name="form1"> <input type="button" id="btn" name="btn" value="get" onClick="gettotal()"/> <input type="text" id="pop" name="pop" size="3"/> <input type="text" id="pop1" name="pop1" size="5" value="val"/> </form>
希望這可以幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.