我想在javascript中添加html标签

时间:2017-07-19 09:10:37

标签: javascript jquery html

所以在这里我得到这个jquery滑动侧面菜单插件,我想在javascript代码上添加span glyphicon,但它转向字符串,任何人都可以帮助我吗?

这是插件代码,它完全是javascript,这就是编辑它的原因很难

<script type="text/javascript">
    // Creating the master menu (SideMenu)
    sideMenu = new SideMenu([
        new SMLabelItem("The First Item Added!")
    ], {
        overlay: true
    });


    // Adding items with events ("Share")
    sideMenu.addItem(new SMSubMenuItem("Share", [
        new SMButtonItem("Facebook", function() {
            window.open('http://www.facebook.com/sharer/sharer.php?u=' + encodeURIComponent(location));
        }, "fb"),
        new SMButtonItem("Twitter", function() {
            window.open('https://twitter.com/intent/tweet?text=SideMenu.js&url=' + encodeURIComponent(location));
        }, "tw"),
        new SMButtonItem("Google+", function() {
            window.open('https://plus.google.com/share?hl=es-419&url=' + encodeURIComponent(location));
        }, "gp"),
        new SMButtonItem("Pinterest", function() {
            alert("Pinterest Share");
        }, "pin")
    ]));



    // Adding mix items ("Animals")
    sideMenu.addItem(new SMSubMenuItem("Animals", [
        new SMLinkItem("Bunny", "https://www.google.com.pe/?#q=Bunny"),
        new SMLinkItem("Tiger", "https://www.google.com.pe/?#q=Tiger"),
        new SMLinkItem("Dog", "https://www.google.com.pe/?#q=Dog"),
        new SMLinkItem("Cat", "https://www.google.com.pe/?#q=Cat", "_blank"),
        new SMSubMenuItem("Birds", [
            new SMLinkItem("Eagle", "https://www.google.com.pe/?#q=eagle"),
            new SMLabelItem("Hawk"),
            new SMLabelItem("Tucan"),
            new SMButtonItem("Parrot", function() {
                alert("Hello World!");
            }),
            new SMLabelItem("Chicken"),
            new SMLabelItem("Duck")
        ]),
        new SMLabelItem("Pig"),
        new SMLinkItem("Crocodile", "https://www.google.com.pe/?#q=Crocodile")
    ]));


    // Adding simple label items
    sideMenu.addItem(new SMSubMenuItem("Continents", [
        new SMLinkItem("Europe","https://www.google.com.pe/?#q=Crocodile"),
        new SMLabelItem("Asia"),
        new SMLabelItem("Africa"),
        new SMSubMenuItem("North America", [
            new SMLabelItem("Canada"),
            new SMLabelItem("Mexico"),
            new SMLabelItem("United States")
        ]),
        new SMLabelItem("Center America"),
        new SMSubMenuItem("South America", [
            new SMLabelItem("Argentina"),
            new SMLabelItem("Bolivia"),
            new SMLabelItem("Brasil"),
            new SMLabelItem("Colombia"),
            new SMLabelItem("Chile"),
            new SMLabelItem("Ecuador"),
            new SMLabelItem("Paraguay"),
            new SMSubMenuItem("Perú", [
                new SMLabelItem("Lima"),
                new SMLabelItem("Trujillo"),
                new SMLabelItem("Loreto"),
                new SMLabelItem("Cuzco"),
                new SMLabelItem("Puno"),
                new SMLabelItem("Cajamarca"),
                new SMLabelItem("etc..")
            ]),
            new SMLabelItem("Uruguay")
        ]),
        new SMLabelItem("Oceanía"),
        new SMLabelItem("Antartida")
    ]));


    // Adding new item
    sideMenu.addItem(
        new SMButtonItem("Download File", function() {
            alert("Go Download File!");
        })
    );



    // Adding new item
    sideMenu.addItem(
        new SMButtonItem("Close", function() {
            sideMenu.close();
        })
    );



    // CUSTOM ITEM
    // This is a custom item example
    // all created custom items extend from SMItem Class.

    SMUserAccountItem = (function(name, src) {
        SMItem.call(this); // Call SMItem constructor
        // this._el is jQuery item object that works how wrapper
        $(this.el).addClass('sm-item-useraccount')
            .append(
                this.photo = $('<img/>')
                .addClass('sm-useraccount-photo')
                .attr({
                    src: src
                }).get(0)
            )
            .append(
                this.name = $('<div/>')
                .addClass('sm-useraccount-name')
                .text(name).get(0)
            );
    });



    // Finally add SideMenu object to DOM tree target.
    $(function() {
        sideMenu.appendTo(document.getElementById('menu'));
    });
</script>
<body>
<div id="menu" class="sm-main"></div>
</body>

1 个答案:

答案 0 :(得分:-1)

试试这个,希望这对你有用;

$('<button />', {

课程:&#39; btn btn-default&#39;,   键入:&#39;按钮&#39;,   id:&#39; test1&#39;,   html:&#39;&#39; });