Should I use [removed] or .value for <textarea>?

前端 未结 3 1077
难免孤独
难免孤独 2020-12-20 22:10

This is a follow-up of Does this not work because I can't use a script in a div?

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



        
相关标签:
3条回答
  • 2020-12-20 22:18

    Javascript innerHTML does update the text in textarea but it doesn't show yours changes in the browser window; if you use it for the second time. for example, If you had some button that updates the text in textarea; this button would insert text for the first time but on second time although it would insert text in textarea (as can be proved by firebug or chrome developer tool) but this would not be shown in browser window. Instead if you use value this would be shown in browser (I had test it in chrome and firefox).

    So I think you should use .value

    0 讨论(0)
  • 2020-12-20 22:23

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

    Try:

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

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

    0 讨论(0)
  • 2020-12-20 22:26

    No idea why you are using eval... below is corrected.. outside of that not sure what you are trying to accomplish. Both value and innerHTML will pull from textareas, the question is what you want only text in the return or possible HTML values.

    function run(){
        document.getElementsByTagName("html")[0].innerHTML += document.getElementById("editorHead").innerHTML;
        document.getElementById("result").innerHTML = document.getElementById("editorBody").innerHTML;
    }
    
    0 讨论(0)
提交回复
热议问题