Home > Article > Web Front-end > Sample code sharing for JavaScript and JQuery method of obtaining DIV value
This article mainly introduces the methods of JavaScript and JQuery to obtain the p value. Combined with specific examples, it compares and analyzes the implementation techniques of javascript and jQuery to obtain the p element value of the page. It requires Friends can refer to the following
The examples in this article describe how to obtain the p value using JavaScript and JQuery. Share it with everyone for your reference, the details are as follows:
1. Sample code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>JavaScript和JQuery获取p的值</title> <script type="text/javascript" src="jquery-1.7.2.min.js"></script> <script type="text/javascript"> $(function(){ $("#jqueryInput").click(function(){ var pValue = $("#p_val").text(); var pVal = $("#p_val").html(); alert("JQuery获取p的值:"+pValue+"\n"+pVal); }); }); function javaScriptp() { var pVal = document.getElementById("p_val").innerHTML; alert("JavaScript获取p的值:"+pVal); } </script> </head> <body> <p id="p_val">www.jb51.net</p> <input type="button" value="JavaScript获取p的值" onclick="javaScriptp()"/> <input type="button" value="JQuery获取p的值" id="jqueryInput"/> </body> </html>
2. Running results:
(1) Initialization
(2) Click the "JavaScript to get the value of p" button
## (3) Click "jQuery to get the value of p" Value "ButtonThe above is the detailed content of Sample code sharing for JavaScript and JQuery method of obtaining DIV value. For more information, please follow other related articles on the PHP Chinese website!