How to use javascript to set text area value in a form in IE

冷暖自知 提交于 2019-12-22 06:59:58

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!