将数据从HTML表单传递到JavaScript! [英] Passing Data from HTML forms to JavaScript!

查看:143
本文介绍了将数据从HTML表单传递到JavaScript!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个XHTML表单,其中包括3个文本框和一个提交按钮.
当按下提交按钮时,必须提交文本框中的数据,并且这些数据应由JavaScript标识,并将这些变量值传递给警报!

There is an XHTML form including 3 text boxes and a submit button.
When the submit button is pressed the data in the text boxes must be submitted and they should identified by JavaScript and should pass those variable values to an alert!

How could I able to do that!

推荐答案

当您说提交时,表示您正在将值发送回服务器.如果要使用JavaScript从字段中获取值并将其显示在警报中,则可以这样做:

When you say submit, you imply you are sending the values back to the server. If you want to use JavaScript to get the values out form fields and present them in an alert, this is what you might do:

<html>
<script>
function showValues() 
{
    alert(document.getElementById('txtMgs').value);
}
</script>

<body><form>

<input type="text" id="txtMsg" />
<input type="button" value="click me!" id="btnRun" onclick="showValues();" />

</form></body></html>


这篇关于将数据从HTML表单传递到JavaScript!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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