Need advice for onclick BBCode Spoiler-Tag in phpBB

时间:2015-10-06 09:04:08

标签: javascript css onclick bbcode

I've implemented this javascript nearly at the bottom of my overall_header.html:

<script lang="javascript" type="text/javascript">
        window.onload = function() {
            var IMG = document.getElementsByTagName('img');
            for (var i=0;i<IMG.length;i++) {
                IMG[i].addEventListener('click',fullImage,false);
            }
            var SPOILER = document.getElementsByClassName('spoiler');
            for (var i=0;i<SPOILER.length;i++) {
                SPOILER[i].addEventListener('click',showSpoiler,false);
            }
        };
        function fullImage() {
            if (this.className == '') {
                this.className = 'full-image';
            } else {
                this.className = '';
            }
        }
        function showSpoiler() {
            if (this.className == 'spoiler') {
                this.className = 'spoiler show';
            } else {
                this.className = 'spoiler';
            }
        }
    </script>

Then I've created a custom BBCode Tag in ACP:

[spoiler]{TEXT}[/spoiler]
<span class="spoiler" onclick="function('showSpoiler');>{TEXT}</span>

Also the corresponding CSS classes in my stylesheet.css

.spoiler { color: #000000; background: #000000; cursor: help; }
.spoiler img { visibility: hidden; pointer-events: none; -webkit-user-select: none; -moz-user-select: none; user-select: none; }
.spoiler.show { text-decoration: none; background: transparent; }
.spoiler.show img { visibility: visible; display: inline-block; -webkit-user-select: all; -moz-user-select: all; user-select: all; pointer-events: all; }

Now what happens is that text marked with a BBcode spoiler tag will be blacked out and when I hover the mouse over it, the cursor will change to the help cursor icon, but nothing happens "onclick". Please can you advise how I can get this stuff finally to work?

Please can you help me? Many thanks in advance!

1 个答案:

答案 0 :(得分:1)

似乎你在span的onclick属性的末尾错过了双引号。

编辑:我已经确定了fiddlechecked。正如您所看到的那样,它按预期工作。我的建议是开始使用IDE(例如NetbeansPHPStormEclipse)或至少一个支持语法高位的编辑器(例如NP++)不要忽视这样的拼写错误..

<span class="spoiler" onclick="function('showSpoiler')">spoilertext</span>

https://jsfiddle.net/wj8oqk7o/