Home > Web Front-end > JS Tutorial > How to set the value of p in javascript

How to set the value of p in javascript

青灯夜游
Release: 2021-10-25 15:08:42
Original
5611 people have browsed it

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 "".

How to set the value of p in javascript

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>
Copy after login

Rendering:

How to set the value of p in javascript

[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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template