Javascript 使用jquery在页面中添加或删除css文件
我想在topHeader div关闭后删除页面加载中的所有css文件,除了topHeader中的一个css文件,因为我已经编写了一些jquery代码,但它不适用于任何人可以帮助吗Javascript 使用jquery在页面中添加或删除css文件,javascript,jquery,html,css,Javascript,Jquery,Html,Css,我想在topHeader div关闭后删除页面加载中的所有css文件,除了topHeader中的一个css文件,因为我已经编写了一些jquery代码,但它不适用于任何人可以帮助吗 <div class="topHeader" style="background-color: #0a5fa2 !important"> <div class="stripe"> <div class="row"> <div cl
<div class="topHeader" style="background-color: #0a5fa2 !important">
<div class="stripe">
<div class="row">
<div class="col-md-4">
<p class="needHelp">Need Help?</p>
<p class="helpDesk">Hotel Reservation Helpdesk (Working Hours TO 8PM)</p>
</div>
<div class="col-md-8">
<div class="wprTopicon">
<span class="whyBookWith">Why book with us ?</span>
<div class="secureTrans">SECURE
<br> TRANSACTIONS</div>
<div class="bestRateGurtee">BEST PRICE
<br>GUARANTEED</div>
<div class="bestOffer">BEST OFFER</div>
</div>
</div>
</div>
</div>
<link rel="stylesheet" type="text/css" href="http://wotfly.com/templates-common/106/css/newheader.css">
</div>//topHeader closed
<link rel="stylesheet" type="text/css" href="http://wotfly.com/templates- common/106/css/newheader.css">
<link rel="stylesheet" type="text/css" href="http://wotfly.com/templates-common/106/css/newheader.css">
<link rel="stylesheet" type="text/css" href="http://wotfly.com/templates-common/106/css/newheader.css">
<link rel="stylesheet" type="text/css" href="http://wotfly.com/templates-common/106/css/newheader.css">
<link rel="stylesheet" type="text/css" href="http://wotfly.com/templates-common/106/css/newheader.css">
<script>
$(function() {
var count = 1;
$('link').each(function() {
var href = $(this).attr('href');
if (href == "http://wotfly.com/templates-common/106/css/newheader.css") {
if (count > 1) {
$(this).remove();
}
count++;
}
});
});
</script>
Remove function is not deleting the css file from the page please help?
需要帮助吗
酒店预订服务台(工作时间至晚上8点)
为什么要和我们一起预订?
保护
交易
最优惠价格
保证
最佳报价
//上收割台已关闭
$(函数(){
var计数=1;
$('link')。每个(函数(){
var href=$(this.attr('href');
如果(href==”http://wotfly.com/templates-common/106/css/newheader.css") {
如果(计数>1){
$(this.remove();
}
计数++;
}
});
});
删除功能不是从页面中删除css文件,请帮助?
有两个问题:
- 您拼错了函数ready
- 链接2上有额外的空间<代码>href=”http://wotfly.com/templates- 通用/
$(函数(){
var计数=1;
$('link')。每个(函数(即,e){
var href=$(this.attr('href');
如果(href==”http://wotfly.com/templates-common/106/css/newheader.css") {
如果(计数>1){
$(this.remove();
}
}
计数++;
});
});
需要帮助吗
酒店预订服务台(工作时间至晚上8点)
为什么要和我们一起预订?
保护
交易
最优惠价格
保证
最佳报价
它应该能工作
var elements=document.querySelectorAll(“链接”);
对于(var i=0;i
需要帮助吗
酒店预订服务台(工作时间至晚上8点)
为什么要和我们一起预订?
保护
交易
最优惠价格
保证
最佳报价
您可以简单地使用:not(:first)
排除第一个链接并删除其余链接
$("link[href*='http://wotfly.com/templates-common/106/css/newheader.css']:not(:first)").remove();
将所有的
样式表
放在
标记中动态生成所有css,我们无法将其放入headtry$(“链接[href*=”http://wotfly.com/templates-common/106/css/newheader.css“]”。删除();
这将使用相同的href删除所有css文件,而我想删除除oneHi之外的所有css文件。谢谢rply,但这不是一个问题……此代码无法删除css文件。还有一件事,请尝试将count++;
置于if语句之外。请参阅更新的代码如果我们使用count,则无法删除服务器上使用javascript或jquery的任何文件++;外部页面也包含如此多的链接,每个循环运行的所有链接和计数都将增加,它将使用给定的href删除所有css文件,而我想删除除一个之外的所有css文件