[英]Jquery to populate input or textarea
<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?
提前致謝!
使用$.val
。 假設#example
是指向相關輸入字段的選擇器,您可以使用以下內容:
$('#example').val(jah);
就像這樣使用jQuery的val方法$('#Id').val(jah);
其中Id是textarea的輸入id。 :)
如果您想使用純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);
$('#myinput').val($('#example').find('p').text());
其中'myinput'是你的textarea的id。 之后粘貼此行
document.getElementById("example").innerHTML=jah;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.