jquery动态添加alt、keywords、description、title
文章目录
1.jquery给img动态添加alt属性
$(document).ready(function(){
$("body img").each(function(){
$(this).attr('alt','11111');
});
});2.动态添加keywords、description关键字
$("meta[http-equiv='X-UA-Compatible']").after(
`<meta name="keywords" content="${keywords}">
<meta name="description" content="${description}">`
);3.动态添加页面title
document.title = 'title';4.动态添加页面title后会卡顿一下闪烁默认title内容,然后才显示我们设置的内容,解决方式可以在html内容之前添加script标签设置title为空,如下:
<script>
document.title = '\u200E';
</script>
评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论