我的代码是在单击标签时使用checked类显示元素。
当我在实时页面中单击☐ tag-name时,没有任何反应。
当我单击jsfiddle中的那个时,它工作得很好。
我不知道Blogger出了什么问题。
有人能帮帮我吗?谢谢。
Blogger live page,jsfiddle:
$('div.label').on('click', function(){
if ( $(this).text().match("☐") ) {
$('div.dhptable table.hptable').show();
$('div.label').each(function(){
$(this).text( $(this).text().replace("☑", "☐") );
});
$(this).text( $(this).text().replace("☐", "☑") );
$('table.hptable:not(.'+$(this).attr("id")+')').hide('slow');
} else {
$('div.dhptable table.hptable').show('slow');
$(this).text( $(this).text().replace("☑", "☐") );
}
})body {
width: 650px;
}
.hptable {
text-align:center;
vertical-align: middle;
margin: 12px;
display: inline-block;
}
.hptable td:hover {
background-color: #CEE9FF;
}
.cell {
vertical-align: middle;
width: 176px;
max-width: 177px;
/*height: 176px;
max-height: 177px;*/
text-align: center;
border: 1px solid #87CEEB !important;
background-color: #D9F9FF;
font-size: large;
font-weight: bold;
}
.hptable img {
vertical-align:middle;
max-width: 175px;
max-height: 175px;
}
div.muri.b textarea.muri {
width: 60px;
height: 30px;
}
div.lang {
display: inline-block;
border: 1px solid #D1D1FF;
padding: 1px;
border-radius: 2px;
}
.label {
display:inline-block;
background: #84E3FF;
position: relative;
}
.label:before {
content: '';
position: absolute;
top: 0; right: 0;
border-top: 11px solid white;
border-left: 11px solid #84E3FF;
width: 0;
}
.label:after {
content: '';
position: absolute;
bottom: 0; right: 0;
border-bottom: 11px solid white;
border-left: 11px solid #84E3FF;
width: 0;
}<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<hr /><b>TAG</b>:<div id='windows' class='label'> ☐ Windows </div> <div id='jquery' class='label'> ☐ jQuery </div> <div id='software' class='label'> ☐ Software </div> <div id='blogger' class='label'> ☐ Blogger </div>
<br />
<hr />
<div class='dhptable' style='text-align: left; vertical-align: middle;'>
<table class="hptable exc windows">
<tr><td class='null cell'>TAG: windows</td></tr></table>
<table class="hptable exc jquery">
<tr><td class='null cell'>TAG: jquery</td></tr></table>
<table class="hptable exc software">
<tr><td class='null cell'>TAG: software</td></tr></table>
<table class="hptable exc software">
<tr><td class='null cell'>TAG: software</td></tr></table>
<table class="hptable exc blogger">
<tr><td class='null cell'>TAG: blogger</td></tr></table>
<table class="hptable exc">
<tr><td class='null cell'>
</td></tr></table>
</div>
发布于 2016-12-19 11:10:59
看起来你不需要等待DOM加载到站点上。您可以尝试将代码包装在ready事件周围。
$(function() {
$('div.label').on('click', function() {
if ($(this).text().match("☐")) {
$('div.dhptable table.hptable').show();
$('div.label').each(function() {
$(this).text($(this).text().replace("☑", "☐"));
});
$(this).text($(this).text().replace("☐", "☑"));
$('table.hptable:not(.' + $(this).attr("id") + ')').hide('slow');
} else {
$('div.dhptable table.hptable').show('slow');
$(this).text($(this).text().replace("☑", "☐"));
}
})
});https://stackoverflow.com/questions/41215214
复制相似问题