<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?
提前致谢!
最佳答案
如果要使用纯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);