[英]html onclick javascript function call to show something
I want to call gettotal function to get value from textbox and * 3 and show the result in other textbox , code does not work where is the problem!?我想调用 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>
Instead of .innerHTML() (used to asign HTML tags to element) use .value
to assign value to an input field like @Azzi mentioned in his answer :而不是.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>
Hope this helps.希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.