问题
I can use this to set a text area (selectedtext) value in a form (submitquestion) if Firefox, but it fails in IE.
document.submitquestion.selectedtext.value = txt;
回答1:
This should work:
<textarea id="bla">from</textarea>
<script type="text/javascript">
document.getElementById("bla").value = "test";
</script>
回答2:
Try this:
document.forms['submitquestion'].elements['selectedtext'].value = txt;
Assuming you have:
<form name='submitquestion'>
<textarea name='selectedtext'></textarea>
</form>
回答3:
I recommend using JQuery, it works with all browsers.
$('#selectedtext').val('whatever');
回答4:
You can do this in pure javascript like this
document.getElementById("myTextarea").value = txt;
来源:https://stackoverflow.com/questions/5589057/how-to-use-javascript-to-set-text-area-value-in-a-form-in-ie