我在一个页面使用javascript为一个文本框赋值,然后点击一个链接进入到另外一个页面,然后使用浏览器的“后退”按钮返回到前一个页面,出现下面的情况:
IE:
被赋值的文本框:有值
用javascript来取这个文本框的值:取不到值FireFox:
被赋值的文本框:有值
用javascript来取这个文本框的值:有值请问这是为什么呢?有什么方法让IE也能取到值吗?
谢谢!
---------------------------------------------
我写了一个简单的代码,可以分别用IE和FireFox运行看到上面的问题,代码如下:
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>Test back button</title>
<script language=javascript>
function additem()
{
var selectCtrl = document.getElementById("selectCtrl");
var selectedText = document.getElementById("selectedText");
selectedText.value = selectCtrl.options[selectCtrl.selectedIndex].text;
}
</script>
</head><body>
1.在列表中双击,选择一个值:<br>
<select size="4" id="selectCtrl" ondblclick="additem();" style="height:120px;width:128px;">
<option value="1">Value 1</option>
<option value="2">Value 2</option>
<option value="3">Value 3</option>
<option value="4">Value 4</option>
<option value="5">Value 5</option>
</select>Selected text:<input id="selectedText" type=text style="width:200px">
<br>
<br>
2.点击下面的链接,转到一个网页(点击之前,请先看一下3.的说明)<br>
<a href="http://www.microsoft.com">Go to a page</a><br>
<br>
3.使用浏览器的“后退” 按钮,回到此页,看看下面的“Last selected text:”后面有没有值?<br>
<div id="backText">Last selected text:</div><script language=javascript>
var selectedText = document.getElementById("selectedText");
var backText= document.getElementById("backText");
backText.innerHTML += selectedText.value;
</script>
</body></html>
IE:
被赋值的文本框:有值
用javascript来取这个文本框的值:取不到值FireFox:
被赋值的文本框:有值
用javascript来取这个文本框的值:有值请问这是为什么呢?有什么方法让IE也能取到值吗?
谢谢!
---------------------------------------------
我写了一个简单的代码,可以分别用IE和FireFox运行看到上面的问题,代码如下:
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>Test back button</title>
<script language=javascript>
function additem()
{
var selectCtrl = document.getElementById("selectCtrl");
var selectedText = document.getElementById("selectedText");
selectedText.value = selectCtrl.options[selectCtrl.selectedIndex].text;
}
</script>
</head><body>
1.在列表中双击,选择一个值:<br>
<select size="4" id="selectCtrl" ondblclick="additem();" style="height:120px;width:128px;">
<option value="1">Value 1</option>
<option value="2">Value 2</option>
<option value="3">Value 3</option>
<option value="4">Value 4</option>
<option value="5">Value 5</option>
</select>Selected text:<input id="selectedText" type=text style="width:200px">
<br>
<br>
2.点击下面的链接,转到一个网页(点击之前,请先看一下3.的说明)<br>
<a href="http://www.microsoft.com">Go to a page</a><br>
<br>
3.使用浏览器的“后退” 按钮,回到此页,看看下面的“Last selected text:”后面有没有值?<br>
<div id="backText">Last selected text:</div><script language=javascript>
var selectedText = document.getElementById("selectedText");
var backText= document.getElementById("backText");
backText.innerHTML += selectedText.value;
</script>
</body></html>
解决方案 »
- gsoap (client)调用wcf服务出错
- 求一个分页控件
- 企业库的安装使用
- 求明白Property 的问题,有了解的进来帮个忙呗~~~~~~~~~~~~~~~~~~~~~~~~~~
- FreeTextBox不能上传图片,哪位帮帮我?我都弄了几天了,不知什么原因?
- 怎么写一个生成静态页时,时时显示当前进度?
- 如何实现象口碑网这样的效果
- 如何用javascript 調用API的 Beep()函數?
- 关于ASP.net中的DropDownList控件[十万火急]
- 为什么打开WEB程序提示 “打开 Web http://localhost:4814 时出错”
- 如何做到当session失效或没有登录时就转到登录页面?
- [馨郁星愿]如何从数据库中取出日期,并对应的转换成星期几?用DataList显示下
function window.onload()
{
document.getElementById("backText").innerHTML = document.getElementById("selectedText").value;
}</script>即可
window.onload = function()
{
document.getElementById("backText").innerHTML += document.getElementById("selectedText").value;
}
</script>不过firefox只记住了第一次的
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>Test back button</title>
<script language=javascript>
function additem()
{
var selectCtrl = document.getElementById("selectCtrl");
var selectedText = document.getElementById("selectedText");
selectedText.value = selectCtrl.options[selectCtrl.selectedIndex].text;
if(navigator.appName!='Microsoft Internet Explorer') window.history.go(0)
}
</script>
</head><body>
1.在列表中双击,选择一个值:<br>
<select size="4" id="selectCtrl" ondblclick="additem();" style="height:120px;width:128px;">
<option value="1">Value 1</option>
<option value="2">Value 2</option>
<option value="3">Value 3</option>
<option value="4">Value 4</option>
<option value="5">Value 5</option>
</select>Selected text:<input id="selectedText" type=text style="width:200px">
<br>
<br>
2.点击下面的链接,转到一个网页(点击之前,请先看一下3.的说明)<br>
<a href="1.htm">Go to a page</a><br>
<br>
3.使用浏览器的“后退” 按钮,回到此页,看看下面的“Last selected text:”后面有没有值?<br>
<div id="backText">Last selected text:</div>
<script language=javascript>
window.onload = function()
{
document.getElementById("backText").innerHTML = document.getElementById("selectedText").value;
}
</script>
</body></html>
最近在用AJAX实现一些功能,好多操作都需要在客户端用javascript来实现,还要考虑浏览器的兼容问题,一会儿到Mac OS X上用Safari和FireFox也试试看。