页面刷新了,页面就不存在了,后面的代码执行不到了。
这个123是后台传过来的值吧?
这个最好把问题分解下,由两个页面完成这个功能,用到AJAX或者是用iframe吧

解决方案 »

  1.   

    我不会ajax和iframe天外,你能帮我写个么?不胜感激
      

  2.   

    这个不太好写,不知道你后台的情况,调试也没办法,这有个以前的例子,服务器端语言是JSP,其他语言也大致差不多的,一共两个文件。FirstAjAx.jsp<%@page contentType="text/html;charset=gb2312"%>
    <script language="javascript">
    var http_request = false;
    function send_request(url) {//初始化、指定处理函数、发送请求的函数
    http_request = false;
    //开始初始化XMLHttpRequest对象
    if(window.XMLHttpRequest) { //Mozilla 浏览器
    http_request = new XMLHttpRequest();
    if (http_request.overrideMimeType) {//设置MiME类别
    http_request.overrideMimeType("text/xml");
    }
    }
    else if (window.ActiveXObject) { // IE浏览器
    try {
    http_request = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
    try {
    http_request = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (e) {}
    }
    }
    if (!http_request) { // 异常,创建对象实例失败
    window.alert("不能创建XMLHttpRequest对象实例.");
    return false;
    }
    http_request.onreadystatechange = processRequest;
    // 确定发送请求的方式和URL以及是否同步执行下段代码
    http_request.open("GET", url, true);
    http_request.send(null);
    }
    // 处理返回信息的函数
        function processRequest() {
            if (http_request.readyState == 4) { // 判断对象状态
                if (http_request.status == 200) { // 信息已经成功返回,开始处理信息
                    alert(http_request.responseText);
                } else { //页面不正常
                    alert("您所请求的页面有异常。");
                }
            }
        }
        function userCheck() {
    var f = document.form1;
    var username = f.username.value;
    if(username=="") {
    window.alert("用户名不能为空。");
    f.username.focus();
    return false;
    }
    else {
    send_request('FirstAjAx2.jsp?username='+username);
    }
    }
        
    </script>
    <form name="form1" action="" method="post">
      用户名:<input type="text" name="username" value="">&nbsp;
      <input type="button" name="check" value="唯一性检查" onClick="userCheck()">
      <input type="submit" name="submit" value="提交">
    </form>
    FirstAjAx2.jsp
    <%@ page contentType="text/html; charset=gb2312" errorPage="" %>
    <%
    String username = request.getParameter("username");
    if("educhina".equals(username)) out.print("用户名已经被注册,请更换一个用户名。");
    else out.print("用户名尚未被使用,您可以继续。");
    %>简单点说
    主要就是这句
    send_request('FirstAjAx2.jsp?username='+username);
    发个请求到一个其他的文件上
    而在FirstAjAx2.jsp中输出一些内容
    如果上面的状态都通过了
    http_request.responseText这个就是在FirstAjAx2.jsp输出的内容,就可以用JS操作他,或输出显示或处理该信息。
      

  3.   

    程序中
    原来刷新的是父页面啊,那不用那么麻烦了。
    问题出在这里
    document.getElementById("td1").value = 123;
    这句后面的分号是全角的
      

  4.   

    现在是直接给值123,
    真正的时候,是从applet里面读值得
    画面上有个applet
    <applet code="ClientApplet.class" name="TestApplet" width = 100 height =100 ></applet>
    每次我按更新按钮后,textarea里面的内容就是把applet里面的值读出来,放入textarea里面
    var strData;
    strData = window.document.TestApplet.GetStringData();
    document.getElementById("td1").value = strData;
      

  5.   

    <html>
    <head>
    <title>Test</title>
    <script language=javascript>function getData(){
    var strData;
    window.parent.location.reload();
    }function test()
    {
             document.getElementById("td1").value = 123;
    }</script>
    </head>
    <body onload="test();">
    <form method = "post" action = "" name = "Fm">
    <input type = "button" value = "更新" onclick = "getData()">
    <textarea name = "td1" rows = 10 cols = 140></textarea>
    </form>
    </body>
    </html>
    错了我不负责啊^^^^^黑黑
      

  6.   

    applet的程序能改吗?
    切换页面才有数据?:)
    是不是程序中要用到父页面的东西?
    而父页面在刷新还在加载,所以会没赋值
      

  7.   

    <input type=button value=刷新 onclick="history.go(0)">
    <input type=button value=刷新 onclick="location.reload()">
    <input type=button value=刷新 onclick="location=location">
    <input type=button value=刷新 onclick="location.assign(location)">
    <input type=button value=刷新 onclick="document.execCommand('Refresh')">
    <input type=button value=刷新 onclick="window.navigate(location)">
    <input type=button value=刷新 onclick="location.replace(location)">
    <input type=button value=刷新 onclick="window.open('自身的文件','_self')">
    <input type=button value=刷新 onClick=document.all.WebBrowser.ExecWB(22,1)> 
    <OBJECT classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 id=WebBrowser width=0></OBJECT>
    <form action="自身的文件">
    <input type=submit value=刷新>
    </form>
    <a id=a1 href="自身的文件"></a>
    <input type=button value=刷新 onclick="a1.click()">
      

  8.   

    不是要改applet的程序阿
    我现在做的是applet跟服务器通信,从服务器上读取某个文件的数据,然后在画面上显示出来。问题是,因为那个文件在不断变化,所以我要做个更新按钮,按了以后,applet要重新读取文件,并且在画面上显示出来。
      

  9.   

    var strData;
    strData = window.document.TestApplet.GetStringData();
    alert(strData)
    document.getElementById("td1").value = strData;
    这段程序看不出什么问题,看看strData 的值能弹出来吗?报的错误原因是什么?
      

  10.   


    用了上面那位仁兄的
    <input type=button value=刷新 onclick="document.execCommand('Refresh')">
    能显示正确了,晕
      

  11.   

    还在调试
    在静态html页面通过了
    放到cgi里面,好像还有问题
      

  12.   

    天外,出问题了
    在静态页面中textarea中有数据,但是放到cgi中,还是没有数据晕
      

  13.   

    静态页面和cgi都是放到服务器上,然后我自己这边访问的
      

  14.   

    要不你把那值get传过去行不??得到当前页面的url
    如果url有td1value则把当前值换上去,没有就加上?td1value=123
    然后location.href=...处理后的url
    页里取td1value再富值