0

Web サービスから結果を取得して div に表示する ajax スクリプトがありますが、入力領域/テキスト フィールドに表示したいと考えています。

私の主なスクリプト:

<script type="text/javascript">
   function get_CODES_Results() {
      document.getElementById("results").innerHTML = "<img src=\'loading.gif\' />";
      var url = document.location;
      if (window.XMLHttpRequest) req = new XMLHttpRequest();
      else if (window.ActiveXObject) req = new ActiveXObject("Microsoft.XMLHTTP");
      req.onreadystatechange = processRequest;
      //req.open("GET", url, true);
      //req.send(null);
      req.open("POST",url,true);
      req.setRequestHeader("Content-type","application/x-www-form-urlencoded");
      req.send("codes="+document.getElementById("codes").value);
      function processRequest() {
         if (req.readyState == 4) {
            document.getElementById("results").innerHTML = req.responseText;
         }
      }
   }
</script>

そして、ここでそれが表示されている領域:

<p>
   <h3>Results:</h3>
   <div id="results"></div>
</p>

私の質問:

結果が入力/テキストフィールドに表示されるようにするにはどうすればよいですか?

アドバイスをいただければ幸いです - ありがとう、パトリック

4

3 に答える 3

2

これを試してください:

document.getElementById("results").value = req.responseText;

そして、あなたの結果は入力でなければなりません:

<input type="text" id="results" />
于 2012-09-01T07:56:17.417 に答える
2

これ?

document.getElementById("results").value = req.responseText;

<input id="results" type="text" />
于 2012-09-01T07:56:26.210 に答える
2

これがテキスト フィールドであるとします。

<input type="text" id="whatever" value="" />

応答をその値に設定するだけです。

document.getElementById('whatever').value = req.responseText;
于 2012-09-01T07:56:44.590 に答える