2015-11-15 114 views
-4

我想调用gettotal函数从文本框和* 3中获取值,并在其他文本框中显示结果,代码不起作用 问题在哪里!?html onclick javascript function call to show something

<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> 
+0

什么是您遇到的具体“不工作”问题?您在浏览器开发者工具中是否收到任何错误? – ajshort

回答

0
<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> 
+0

仍然不能正常工作 –

+0

谢谢你的帮助它的工作原理...值不innerHTML –

0

而不是.innerHTML()(用于ASIGN 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>

希望这会有所帮助。