如何在html表中分配脚本变量值 [英] How to assign a script variable value inside an html table

查看:80
本文介绍了如何在html表中分配脚本变量值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我使用的是HTML 4.01。在HTML中我调用了函数并返回一个字符串值。返回值在名为var returnValue的变量中捕获。当我弹出一个带警报功能的消息时,我的'returnValue'有预期的输出值。



现在我的问题是,我希望HTML中的'returnValue'变量值表。当我在td(表数据)中编写代码时

returnValue
它不显示变量的值,因为它在html输出页面中显示变量名称。我尝试了不同的东西,但它们都没有用,我在HTML和Javascript方面的知识也不好。任何人都可以帮我在HTML表数据中显示脚本可变值。



先谢谢。

Hi,
I am using HTML 4.01. In HTML i called and function which returns a string value. The return value is captured in a variable named 'var returnValue'. When i popup a message with alert function, my 'returnValue' has expected output value.

Now my question is, i want value of 'returnValue' variable inside an HTML table. When i wrote code inside td (table data)
"

returnValue
" it is not displaying the value of the variable where as it is displaying the variable name in the html output page. I tried different things but none of them works and my knowledge in HTML and Javascript is not good. Can anybody help me to display a script vaiable value inside an HTML table data.

Thanks in Advance.

推荐答案

试试这个:

Try this:
<!DOCTYPE html>
<html>
<head>
<script>
function concat(){
    var first= document.getElementById("first").value;
    var second = document.getElementById("second").value;
    var result = document.getElementById("result");
    result.innerText = first + " " + second;
}
</script>
</head>
<body>
<input type="text" id="first" value="hello">
<input type="text" id="second" value="world">
<button onclick="concat()">Concat</button>
<div id="result">waiting for result</div>
</body>
</html> 


试试这个对我有用!!



字符串结果= function(); / / function return string

< tr>< td>+ result +< / td>< / tr>
Try this it worked for me!!

String result = function();//function return string
"<tr><td>"+result+"</td></tr>"


这篇关于如何在html表中分配脚本变量值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆