1  function data_handle(x){
2    var value_1=document.getElementById(x).value;
3    value_1=value_1.toUpperCase();  
4    document.getElementById(x).value=value_1;  //使输入到x的内容不区分大小写
5
6    var fen="fen"+i;
7    //这里需要读库,获得数据 var data
8    document.getElementById(fen).value="获取data";
9    //document.getElementById(fen).value=100; 这样测试正常。
10    这里的x和fen都是文本框。
11  }12  注释部分的内容是一段php,在另一个文件getdata.php里:
13  include("conn.php");
14  $resault=mysql_query("SELECT * FROM ... WHERE `filed`='js里的value_1' LIMIT 1",$link)or die(...);
15  $date=mysql_fetch_array($resault);
16  $value_2=$data[5];
17  把$value_2写到上面的第8行等号后面
18  即:
20  document.getElementById(fen).value=$value_2;
21  各位高手,怎么弄?

解决方案 »

  1.   

    用AFAX可以。function initAjax(){
    var ajax = false;
    try{
    ajax = new ActiveXObject("Msxml2.XMLHTTP");
    }catch(e){
    try{
    ajax = new ActiveXObject("Microsoft.XMLHTTP");
    }catch(E){
    ajax = false;
    }
    }
    if(!ajax && typeof XMLHttpRequest != 'undefined'){
    ajax = new XMLHttpRequest();
    }
    return ajax;
    }
    function data_handle(x){
            var value_1=document.getElementById(x).value;
            value_1=value_1.toUpperCase(); 
            document.getElementById(x).value=value_1;  
            var fen="fen"+i;//这个i是哪来的
    var ajax = initAjax();
    ajax.open("post","getdata.php",true);
    ajax.onreadystatechange=function(){
    if(ajax.readyState==4 && ajax.status==200){
     document.getElementById(fen).value
    =decodeURIComponent(ajax.responseText);
    }
    }
    ajax.send(null);
    }
    getdata.php页面:
    <?php
    include_once("conn.php");
    $resault=mysql_query("SELECT * FROM ... WHERE `filed`='js里的value_1' LIMIT 1",$link)or die(...);
    $date=mysql_fetch_array($resault);
    $value_2=$data[5]; 
    echo $value_2;
    ?>
      

  2.   

      var fen="fen"+i;//这个i是哪来的
    i是全局变量。没有问题。
      

  3.   

    可以用jquery 写的代码量少很多...
    复制代码另存为网页就可以用了...
    (注意目录下要有getdata.php,jquery的404错误不显示,需要自己判断)
    <!--jquery -->
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script><script type="text/javascript">
    $(document).ready(function(){
        data_handle();
    });
    function data_handle(){
        /*
        * 转换为大写
        * $('#x').val() 取值
        * $('#x').val().toUpperCase() 转大写
        * $('#x').val($(this).val().toUpperCase()) 赋值
        */
        //alert($('#x').val().toUpperCase());        //debug
        $('#x').val($('#x').val().toUpperCase());

        var fen="fen"+i;    //提交url
        var url = 'getdata.php';    //ajax的post提交
        $.post(url,function(data){
                //赋值
                //alert(data);            //debug
                $('#fen').val(data);
            }
        );    
    }
    </script>
    <input type="text" value="asd" id="x" />
    <input type="text" value="123" id="fen" />
    getdata.php页面:<?php
    include_once("conn.php");
    $resault=mysql_query("SELECT * FROM ... WHERE `filed`='js里的value_1' LIMIT 1",$link)or die(...);
    $date=mysql_fetch_array($resault);
    $value_2=$data[5]; 
    echo $value_2;
    //页面打印的内容即为上面ajax获取的data
    ?>