如何修改这个读更多的js

时间:2015-09-18 20:24:43

标签: javascript php

http://jsfiddle.net/raininglemons/wutu9k7k/

(function () {
    var buttons = document.getElementsByTagName("button");

    for (var i = 0; i < buttons.length; i++) {
        // Find .readmore parent
        var parent = buttons[i].parentElement;
        while (parent !== null && !parent.className.match("readmore"))
            parent = parent.parentElement;

        // Reached top of dom tree and didn't find .readmore element
        if (parent === null)
            continue;

        buttons[i].addEventListener("click", function (event) {
            // Cancel default button behaviour
            event.preventDefault();

            // Add .showall class to parent
            parent.className = parent.className + " showall";
        });
    }
})();

这只显示所有内容和按钮消失。我希望通过按相同的按钮来隐藏内容,只是为了回到原始状态。

0 个答案:

没有答案