js修改html title的方法:1、使用“document.title=需要设置的值;”语句;2、使用“$('title').html('需要设置的值')”或“$('title').text('需要设置的值')”语句。
本教程操作环境:windows7系统、javascript1.8.5&&jquery1.7.2版、dell g3电脑。
方法1:document.title方式
经过测试,还可通过document.title 设置title的值。
document.title = '需要设置的值';
例子
<!doctype html><html> <head> <meta charset="utf-8"> <title>hello</title> </head> <body> <script type="text/javascript"> document.title = ''; </script> </body></html>
方法2:利用jquery的html()或text()方法
当然如果你的项目里面依赖jquery,可以使用jq的方法设置。
jq中两种方式都可以实现
$('title').html('需要设置的值')$('title').text('需要设置的值')
例子
<!doctype html><html> <head> <meta charset="utf-8"> <title>hello</title> <script src="js/jquery-1.7.2.min.js"></script> </head> <body> <script type="text/javascript"> // $('title').html(''); $('title').text(''); </script> </body></html>
【推荐学习:javascript高级教程】
以上就是js怎么修改html的title标题的详细内容。