2012-05-11 157 views
5
<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填充输入或文本区域

在此先感谢!

+0

我稍微困惑,因为你在标题问jQuery的,但那么你的例子是纯粹的JavaScript。 – Moni

回答

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);

0
$('#myinput').val($('#example').find('p').text()); 

其中'myinput'是您的textarea的id。粘贴此行后

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

通过使用$.val。假设#example指向有问题的输入字段选择器,你可以使用这样的事情:

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

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

其中,ID是textarea的输入ID。 :)