我在一个asp页面上工作,我想用"meta http-equiv="X-UA-Compatible“content="IE=8"”覆盖其中一个页面中的"meta http-equiv="X-UA-Compatible“content="IE=10"”。有可能吗?我尝试了以下几种方法,但都没有成功。
window.onload = function(e){
$('meta[http-equiv="X-UA-Compatible"]').remove();
$('head').append('<meta http-equiv="X-UA-Compatible" content="IE=10">')
}发布于 2018-12-11 07:19:54
这是可能的,但您需要调用.remove() (错过了())
虽然我不确定你希望完成的事情是否会真正起作用(如果你想让IE的行为有所不同)
发布于 2018-12-11 07:28:34
试着这样做:
jQuery
if (window.location.pathname === 'myPage') { // URL is example.com/myPage
$('meta[http-equiv="X-UA-Compatible"]').replaceWith('<meta http-equiv="X-UA-Compatible" content="IE=10">');
}Vanilla JS
if (window.location.pathname === 'myPage') { // URL is example.com/myPage
document.querySelector('meta[http-equiv="X-UA-Compatible"]').outerHTML = '<meta http-equiv="X-UA-Compatible" content="IE=10">';
}发布于 2018-12-11 07:29:14
将您的答案放在$(document).ready()中。由于您使用的是jQuery,因此可以执行以下操作:
$(function() {
$('meta[http-equiv="X-UA-Compatible"]').remove();
$('head').append('<meta http-equiv="X-UA-Compatible" content="IE=10">');
});关于window.onload和$(document).ready()之间的区别,这里有一个很好的解释:window.onload vs $(document).ready()
https://stackoverflow.com/questions/53715077
复制相似问题