我应该为< textarea>使用.innerHTML还是.value? [英] Should I use .innerHTML or .value for <textarea>?

查看:127
本文介绍了我应该为< textarea>使用.innerHTML还是.value?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是后续的这不起作用,因为我不能在一个div中使用脚本吗?

在我离开的时候,我有这样的代码:<
按钮脚本:

Where I left off, I had this code:
Button script:

<script>
    var correctProperty = "value";
    function run(){
        document.getElementsByTagName("head")["0"].innerHTML += eval(document.getElementById("editorHead")[correctProperty]);
        document.getElementById("result").innerHTML = eval(document.getElementById("editorBody")[correctProperty]);
    }
</script>

textareas(没有 class 样式属性和在非div文本之间):

The textareas (without class and style attributes & in between non-div text):

<textarea id="editorHead" rows="20"></textarea>
<textarea id="editorBody" rows="20"></textarea>
<div id="result"></div>

目前这是行不通的,我之前的一个答案(接受的答案) correctProperty 应设为innerHTML。所以呢?或者问题是干扰 window (像以前一样)?或者,我应该把它放在表单中,然后使用value

Currently this doesn't work, and one of my answers from before (the accepted one) said that correctProperty should be set to "innerHTML". So should it? Or is the problem an interference with window (like before)? Or, ... should I put it in a form and then use "value"?

推荐答案

您可以通过value属性访问并更新textarea元素的值。

You access and update the value of a textarea element through the "value" property.

尝试:

Try:

 var theValue = document.getElementById("editorHead").value;

更新< html> 元素doesn没什么意义。

Updating the <html> element doesn't make much sense.

这篇关于我应该为&lt; textarea&gt;使用.innerHTML还是.value?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆