求助!js无法获取<textarea></textarea>中的值

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Get weather information (GWI) </title>
    <style>
    #testarea {
        margin: 0px; 
        width: 1541px; 
        height: 404px;
    }
    #submit {
        height: 12px;
        width: 6px;
    }
    </style>
</head>
<body>
    <?php 
        require('functionDefine.php');

        $requestKey = array(
            array(//www.heweather.com 
                array(
                    'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
                    'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
                    'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
                )
            ),
            array(//www.seniverse.com 心知天气
                'null'
            )
        );

        $requestFull = array();

        $i=0;

        $result=requestByKey($requestKey[0][0][$i]);

        if($result == "no more request"){
            $i++;
            $bool = false;
            while($bool == false){
                $result = $requestKey[0][0][$i];
                if($result == "no more request"){
                    $requestFull[$i] = true;
                    for ($j=0; $j < 3; $j++) { 
                        if($requestFull[$j] == true){
                            $resultBool = $j;
                            if($resultBool = 2){
                                $bool = false;
                                break;
                            }
                        }
                    }
                    $bool = false;
                }
                else{
                    $bool = true;
                }
                $i++;
            }
        }




        makeFile();
        ?><br/>
        <form action="weather.php" method="get" onsubmit="GWI()">
        <textarea name="textarea" id="textarea" cols="30" rows="2" readonly disable onload="GWI()">
            <?php echo requestByKey($requestKey[0][0][0]); ?>
        </textarea><br/>
        <input type="submit" value="submit">
        </form>
        <br/>
        <script>
        function GWI(){
            var x = window.document.getElementById("textarea").value;
            var Bool = true;
            if(this.location.href = 'http://localhost/weather/weather.php'){
                Bool = false;
            }
            var string = "http://localhost/weather/weather.php?wea="  + x +"&data=true";
            if(Bool != false ){
                location.href=string;
            }
        }
        </script><br/>
</body>
</html>

这是我的index.php,这里面的var x = window.document.getElementById("textarea").value;总是获取不到#teatarea中的值。同时,location.href=string再跳转的时候总会把 ?wea=*************&data=true丢掉

function requestByKey($requestKey){
    //准备请求参数
    $key = $requestKey;
    $location = "********";
    $curlPost = "key=".$key."&location=".urlencode($location);
    $req=curl_init();
    curl_setopt($req, CURLOPT_URL,'https://free-api.heweather.net/s6/weather/now?'.$curlPost);
    curl_setopt($req, CURLOPT_TIMEOUT,3);
    curl_setopt($req, CURLOPT_CONNECTTIMEOUT,10);
    $headers=array( "Accept: application/json", "Content-Type: application/json;charset=UTF-8" );
    curl_setopt($req, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($req, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($req, CURLOPT_SSL_VERIFYHOST, false);
    $data = curl_exec($req);
    curl_close($req);
    //global $data;
    return $data;
}

这是requestByKey函数的定义(官方API文档中给的)

发布了1 篇原创文章 · 获赞 0 · 访问量 22

猜你喜欢

转载自blog.csdn.net/weixin_40742472/article/details/104490185