获取文本框的值到另一个html文件
Getting the value of textbox to another html file
我在index.html中有一个文本框,我想获得它的值,并将其放在另一个html文件result.html中的文本框中。(他们有相同的。js文件使用)
index . html文本框:
<input id="txt2" readonly="true" type="number" value="0" name="score" style="border:none;background-color:#f0f2f7">
result.html文本框:
<input id="txt3" readonly="true" type="number" value="0" name="score" style="border:none;background-color:#f0f2f7"></td>
这是自动转到另一个页面的代码:
if((mins == 0) && (secs == 0)) {
//window.alert("Time is up.Your score is "+score); // change timeout message as required
document.getElementById('txt2').value = score;
window.location = "score.html" // redirects to specified page once timer ends and ok button is pressed
}
else {
cd = setTimeout("redo()",1000);
}
和如何将txt3得到txt2的值,因为他们是在不同的html?
像这样使用查询字符串
http://mysite.com/index.html?name=john
并通过使用javascript
在不同的HTML页面上获取此名称function loadPageVar (sVar) {
return unescape(window.location.search.replace(new RegExp("^(?:.*[&''?]" + escape(sVar).replace(/['.'+'*]/g, "''$&") + "(?:''=([^&]*))?)?.*$", "i"), "$1"));
}
// Would alert the value of QueryString-variable called name
alert(loadPageVar("name"));
更改结果页URL如下;
window.location = "result.html?val="+document.getElementById('txt2').value;
result.html
<input id="txt3" readonly="true" type="number" value="0" name="score" style="border:none;background-color:#f0f2f7"></td>
<script>
document.getElementById('txt3').value=window.location.search.replace("?val=","");
</script>
相关文章:
- 使用javascript将动态表从一个html页面打印到另一个html页
- 将html元素插入到文本字符串中,以匹配另一个html字符串
- 如何在另一个html文件的框架中包含图像
- 重定向到Angular JS中的另一个HTML页面
- 使用JavaScript打开另一个html页面时传递变量
- 如何在另一个 html 标签内选择 web 元素硒 Web 驱动程序与 html 源
- 显示从 HTML 表单到另一个 HTML 表单的发布值
- 收到事件时加载另一个.html页面
- 为什么谷歌跟踪代码管理器不能安装在正文下的另一个HTML元素中
- 获取另一个html标记下的html元素值
- 使用angularjs将HTML表单数据从页面提交到另一个HTML页面
- 在我的html页面-web应用程序用户界面的一个选项卡中的另一个html页面中的选项卡
- 调用另一个HTML文件中的函数
- 如何从使用jquery load()加载的另一个html页面执行在主html文件中编写的脚本
- 将NG打印的数据在一个html中重复传输到另一个html
- 在href跳转到另一个html元素之前,执行Knockout.js数据绑定:点击函数
- 用javascript(不带外部文件)将html加载到另一个html中
- 正在检测Html元素是否与另一个Html元件重叠
- 如何在屏幕大小上将html文件更改为另一个html文件
- 禁用来自另一个html页面的html框架的超链接