我需要在jquery中找到正确的代码,这样我就可以在样式表之间快速切换按钮。我目前没有jquery,因为我所有的都失败了。我还在学呢。总之,这里是html:
/* Theme 1 */
body {
background: #ff4455;
}
/* Theme 2 */
body {
background: #ee7744;
}<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<body>
<input type="button" id="theme1">
<input type="button" id="theme2">
<script type="text/javascript"></script>
</body>
下面是代码的一个片段。我需要<script type="text/javascript"></script>内部的jquery
谢谢你的帮助!
发布于 2015-10-22 02:12:09
尝试使用style元素,并将type设置为text/plain;单击input type="button" set style type="text/css"以文本形式显示class与input type="button"的id相同的内容。方法维护同一文档中的所有css,无需在样式的每个切换处请求外部样式表。
$("input[type=button]").click(function() {
$("[type$=css]").text($("." + this.id).text())
})<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<style type="text/css">
</style>
<style type="text/plain" class="theme1">
/* Theme 1 */
body { background: #ff4455; }
</style>
<style type="text/plain" class="theme2">
/* Theme 2 */
body { background: #ee7744; }
</style>
<body>
<input type="button" id="theme1" value="theme1">
<input type="button" id="theme2" value="theme2">
</body>
发布于 2015-10-22 01:59:41
发布于 2015-10-22 02:05:09
应该有许多类似的问题和答案,这里有一个无论如何。
<html>
<head>
<link href="css/sheet1.css" rel="stylesheet" type="text/css" id="sheet1">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
</head>
<body>
<input type="button" id="theme1">
<input type="button" id="theme2">
<script type="text/javascript">
$(document).ready(function () {
$('#theme1').click(function(){
$('#sheet2').remove();
$('head').append('<link href="css/sheet1.css" rel="stylesheet" id="sheet1" />');
});
$('#theme2').click(function(){
$('#sheet1').remove();
$('head').append('<link href="css/sheet1.css" rel="stylesheet" id="sheet2" />');
});
});
</script>
</body>
</html>https://stackoverflow.com/questions/33272156
复制相似问题