Javascript Jquery 填充输入或文本区域
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10545573/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Jquery to populate input or textarea
提问by jahrichie
<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>
I'm using the above code to compile some browser info I need to collect from a form. How can I get that info passed to a Input or Textarea?
我正在使用上面的代码来编译一些我需要从表单中收集的浏览器信息。如何将该信息传递给 Input 或 Textarea?
Thanks in advance!
提前致谢!
采纳答案by XiaoChi
If you want to use pure JavaScript instead of jQuery, try this:
如果你想使用纯 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>
Assigning .value
equals jQuery function .val(v);
赋值.value
等于 jQuery 函数.val(v);
回答by rjz
回答by Prasenjit Kumar Nag
回答by Mr Coder
$('#myinput').val($('#example').find('p').text());
where 'myinput' is id of your textarea. Paste this line after
其中 'myinput' 是你的 textarea 的 id。将此行粘贴到
document.getElementById("example").innerHTML=jah;