首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Blogger - jQuery没有输出?

Blogger - jQuery没有输出?
EN

Stack Overflow用户
提问于 2016-12-19 11:02:49
回答 1查看 61关注 0票数 0

我的代码是在单击标签时使用checked类显示元素。

当我在实时页面中单击☐ tag-name时,没有任何反应。

当我单击jsfiddle中的那个时,它工作得很好。

我不知道Blogger出了什么问题。

有人能帮帮我吗?谢谢。

Blogger live page,jsfiddle:

代码语言:javascript
复制
$('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("☑", "☐") );
  }
})
代码语言:javascript
复制
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;
}
代码语言:javascript
复制
<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'>&nbsp;☐ Windows </div> <div id='jquery' class='label'>&nbsp;☐ jQuery </div> <div id='software' class='label'>&nbsp;☐ Software </div> <div id='blogger' class='label'>&nbsp;☐ 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>

EN

回答 1

Stack Overflow用户

发布于 2016-12-19 11:10:59

看起来你不需要等待DOM加载到站点上。您可以尝试将代码包装在ready事件周围。

代码语言:javascript
复制
$(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("☑", "☐"));
        }
    })
});
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41215214

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档