1

単一のボタンを介して、jquery を使用して css リンクを切り替えたい。

キャッチは、iframeのターゲットでやりたいです。

これまでのところ、リンクをうまく挿入する次のコードがあります。

$("#custom").click(function() {
    $("#content").contents().find("head").prepend("<link href=\"../build/css/custom.css\" rel=\"stylesheet\" id=\"custom-css\">");
});

これは、次の html によってアクティブ化されます。

<div class="toggle-custom">
<a target="custom" id="custom" class="btn btn-primary btn-lg">Toggle custom style</a>
</div>
<iframe id="content" src="carousel.html" frameborder="0" scrolling="auto">
</iframe>

それを削除する方法は次のとおりです。

$("#content").contents().find("#custom-css").remove();

しかし、どうすれば同じボタンから切り替えることができますか?

ありがとう

4

3 に答える 3

1

試す

var contents = $("#content").contents();
var ccss = contents.find("head").find("#custom-css");
if(ccss.length){
    ccss.remove()
} else {
    contents.find("head").prepend("<link href=\"../build/css/custom.css\" rel=\"stylesheet\" id=\"custom-css\">");
}
于 2013-08-23T23:58:20.050 に答える
0

リンクを html に配置し、クリックで切り替えます。

$(document).ready(function(){
    $('#custom-css').hide();
    $("#custom").click(function() {
        $('#custom-css').toggle();
    });
});
于 2013-08-24T00:01:54.950 に答える