从HTML表单中抓取数据并在JavaScript函数中使用 [英] Grabbing data from HTML form and using within JavaScript Function

查看:117
本文介绍了从HTML表单中抓取数据并在JavaScript函数中使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下HTML页面,它使用XHTML 1.0,用于从HTML表单中获取值并使用JavaScript函数显示它。 JS函数和完整的源代码如下所示。



I have following HTML page that uses XHTML 1.0 that used to grab a value from an HTML form and display it using a JavaScript function. The JS function and the full source code is at the below.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title><!-- Insert your title here --></title>
    <script type="text/javascript">
        
        function testVariable(){
            
            var strText = document.getElementById("textone");
            document.write(strText);
                    
        }
        
        
    </script>
</head>

<body>

<form action="" method="get" >
    
    <input type="text" id="textone" name="textone"></input>
    <input type="button" value="Submit" onclick="testVariable();false"></input>
      
</form> 
</body>
</html>





但我的输出如下所示。



-----输出--------



[object HTMLInputElement]



-------------------



我无法弄清楚我做错了什么。那么有人可以帮我解决这个问题吗?



谢谢&问候,

Chiranthaka。



But my output is like at the below.

-----Output--------

[object HTMLInputElement]

-------------------

I can't figure out what I ahve done wrong. So could someone help me to solve this matter?

Thanks & regards,
Chiranthaka.

推荐答案

你正在打印控制对象,应该是它的价值:

You were printing the control object, should be its value instead:
document.write(strText.value);


演示 [ ^ ]

试试

Demo[^]
try with
document.write(strText.value);


这篇关于从HTML表单中抓取数据并在JavaScript函数中使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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