【问题标题】:Jquery to populate input or textareaJquery 填充输入或文本区域
【发布时间】:2017-11-30 04:28:35
【问题描述】:
<div id="example"></div>
  <script type="text/javascript">
             jah = "<p>Browser CodeName: " + navigator.appCodeName + "</p>";
             jah+= "<p>Browser Name: " + navigator.appName + "</p>";
             jah+= "<p>Browser Version: " + navigator.appVersion + "</p>";
             jah+= "<p>Cookies Enabled: " + navigator.cookieEnabled + "</p>";
             jah+= "<p>Platform: " + navigator.platform + "</p>";
             jah+= "<p>User-agent header: " + navigator.userAgent + "</p>";

             document.getElementById("example").innerHTML=jah;

             </script>

我正在使用上面的代码来编译一些我需要从表单中收集的浏览器信息。如何将该信息传递给 Input 或 Textarea?

提前致谢!

【问题讨论】:

  • 我有点困惑,因为您在标题中要求使用 jQuery,但您的示例完全是关于纯 javascript。

标签: javascript jquery


【解决方案1】:

通过使用$.val。假设#example 是一个指向相关输入字段的选择器,您可以使用如下内容:

$('#example').val(jah);

【讨论】:

    【解决方案2】:

    如果你想使用纯 JavaScript 而不是 jQuery,试试这个:

    <form><textarea id="ta"></textarea></form>
    <script type="text/javascript">
        jah = "whatever you want";
        var ta = document.getElementById('ta');
        ta.value = jah;
    </script>
    

    分配.value等于jQuery函数.val(v);

    【讨论】:

      【解决方案3】:

      就像这样使用jQuery的val方法$('#Id').val(jah);

      其中 Id 是 textarea 的输入 id。 :)

      【讨论】:

        【解决方案4】:
        $('#myinput').val($('#example').find('p').text());
        

        'myinput' 是你的文本区域的 id。将这一行粘贴到

        document.getElementById("example").innerHTML=jah;
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2016-04-12
          • 1970-01-01
          • 2013-03-31
          • 1970-01-01
          • 1970-01-01
          • 2017-06-01
          • 2023-03-21
          • 1970-01-01
          相关资源
          最近更新 更多