Change the Value of h1 Element within a Form with JavaScript

梦想与她 提交于 2019-12-31 12:57:11

问题


I have two forms on an HTML5 page. Each form has a name and an id. The second form has an h1 element, which also has a name and an id. How do I change the text of this h1 element on the second form using plain JavaScript?


回答1:


Try:


document.getElementById("yourH1_element_Id").innerHTML = "yourTextHere";




回答2:


You can use this: document.getElementById('h1_id').innerHTML = 'the new text';




回答3:


document.getElementById("myh1id").innerHTML = "my text"



回答4:


You may try the following:

document.getElementById("your_h1_id").innerHTML = "your new text here"



回答5:


You can do it with regular JavaScript this way:

document.getElementById('h1_id').innerHTML = 'h1 content here';

Here is the doc for getElementById and the innerHTML property.

The innerHTML property description:

A DOMString containing the HTML serialization of the element's descendants. Setting the value of innerHTML removes all of the element's descendants and replaces them with nodes constructed by parsing the HTML given in the string htmlString.



来源:https://stackoverflow.com/questions/9529327/change-the-value-of-h1-element-within-a-form-with-javascript

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