Home >Backend Development >PHP Problem >How to dynamically modify the title of a web page in php
How to dynamically modify the title of a web page in php: 1. Use js method, the code is [document.title = 'hello world!']; 2. Use jQuery method, the code is [
#php method to dynamically modify the title of a web page:
1 , js way
First, I thought of using document.getElementsByTagName()
to get the title tag of the page, which can be obtained. For example:
<title>标题</title> <script> var Title = document.getElementsByTagName('title') console.log(Title) // <title>标题</title> </script>
However, When I want to use Title.title to get or set the value, it does not take effect.
Get the title value: console.log(Title.title)
You will find that the value cannot be obtained
Similarly, set the title value of the web page: Title.title = 'hello world!'
You will find that the title of the web page has not been changed
So through this method It is impossible to obtain and change the title of the web page.
In fact, we can directly obtain the title value or set the title value through document.title
<title>标题</title> <script> document.title = 'hello world!' </script>
Result:
【Related learning recommendation: js video tutorial】
It can be found that this method is feasible.
2. jQuery method
<title>标题</title> <script src="//m.sbmmt.com/jquery/3.2.1/jquery.js"></script> <script> $(function(){ $('title').html('hello!') // 此处也可以使用text()方法 }) </script>
Relevant learning recommendations: php programming (video), jQuery video tutorial
The above is the detailed content of How to dynamically modify the title of a web page in php. For more information, please follow other related articles on the PHP Chinese website!