How to set the p value in javascript: 1. Use the getElementById() method to obtain the p element object according to the specified id; 2. Use the innerText attribute to set the value of the p element object, the syntax is "p element object.innerText=" The value that needs to be set is "".
The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.
javascript sets the value of p
First use the getElementById() method to obtain the p element object based on the specified id;
Then use the innerText property to set the value of the p element object.
Implementation code:
<p id="demo">p标签初始值</p><br> <input type="button" value="点击按钮改变p值" onclick="a()"/> <script type="text/javascript"> function a(){ var p=document.getElementById("demo"); p.innerText="欢迎来到PHP中文网!" } </script>
Rendering:
[Recommended learning: javascript advanced tutorial 】
The above is the detailed content of How to set the value of p in javascript. For more information, please follow other related articles on the PHP Chinese website!