我想在脚本中使用多个函数。我没有在第二个文本框中获取计算值。我不知道我的程序有什么问题。 不返回任何值。
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script>
function fun1()
{
var z=5;
function fun3(x)
{
alert("i am fun3");
var y=x+z;
}
return y;
}
function fun2()
{
var a = document.getElementById("txt1").value;
var result = fun3(a);
document.getElementById("txt2").innerHTML=result;
}
</script>
</head>
<body>
Enter no: <input type="text" value="" id="txt1" onkeydown="fun2();">
Result: <input type="text" value="" id="txt2" />
</body>
</html>
最佳答案
你在找这样的东西吗?
function fun1(a)
{
var z=5, y;
function fun3(x)
{
alert("i am fun3");
y=x+z;
}
fun3(a)
return y;
}
function fun2()
{
var a = document.getElementById("txt1").value;
var result = fun1(a);
document.getElementById("txt2").value=result;
}
编辑:
我更改了:document.getElementById("txt2").innerHtml=result;
为 document.getElementById("txt2").value=result;
因为 txt2 是一个input
如果没有,请准确说明您的问题,我会在获得更多详细信息后立即对其进行编辑。
编辑 2
@Nitish 自己发现完成:jsfiddle.net/nitishkaushik/4sxb9d55/4
关于javascript - javascript 中的多个函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31203767/