<html xmlns="
http://www.w3.org/1999/xhtml" >
<head>
<title>未命名页面</title>
<script language="javascript" type="text/javascript">
var t;
function setValue()
{
t = document.getElementById("tt").value;
alert(t);
}
</script>
</head>
<body>
<form id="form1">
<div>
<input type="text" id="tt" value="10" />
<input type="button" id="btnSub" value="提交" onclick="setValue()" />
</div>
</form>
</body>
</html>
点击“提交”按钮,文本框内的值将会赋给<head></head>标签内脚本变量 t 。你可以将此代码复制到文本文件里然后另存为.html,打开.html文件进行测试。本回答被提问者采纳