I've two separate HTML file and .js file. I have a calculate method which return the result in the javascript file.
我有两个单独的HTML文件和.js文件。我有一个计算方法,它返回javascript文件中的结果。
My question is how to set a textbox value from a javascript return value. Or at least from a separate javascript file. Initially I tried below which doesn't work as javascript and html are separated.
我的问题是如何从javascript返回值设置文本框值。或至少从单独的javascript文件。最初我尝试下面的功能不起作用,因为javascript和html是分开的。
function Calculate(ch)
{
//...
document.getElementById('Input').value = resultValue;
}
Thanks!
谢谢!
3 个解决方案
#1
2
eval is the soution for my problem. Input.value = eval(Calculate(ch))
eval是我问题的源泉。 Input.value = eval(Calculate(ch))
#2
0
try to define the js-file in the bottom of your html-file (near the </body>). if you defined it above the targeted element its unknown. this may help.
尝试在html文件的底部(靠近 )定义js文件。如果你在目标元素之上定义它的未知数。这可能有所帮助。
felix
费利克斯
#3
0
Access textarea contents using the innerHTML
property, not the value
property.
使用innerHTML属性访问textarea内容,而不是value属性。
function Calculate(ch) {
//...
document.getElementById('Input').innerHTML = resultValue;
}
#1
2
eval is the soution for my problem. Input.value = eval(Calculate(ch))
eval是我问题的源泉。 Input.value = eval(Calculate(ch))
#2
0
try to define the js-file in the bottom of your html-file (near the </body>). if you defined it above the targeted element its unknown. this may help.
尝试在html文件的底部(靠近 )定义js文件。如果你在目标元素之上定义它的未知数。这可能有所帮助。
felix
费利克斯
#3
0
Access textarea contents using the innerHTML
property, not the value
property.
使用innerHTML属性访问textarea内容,而不是value属性。
function Calculate(ch) {
//...
document.getElementById('Input').innerHTML = resultValue;
}