admin管理员组

文章数量:1316840

Small part of my html code :

<div class="text-center">

        <div class="btn-group">
            <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
                Platforms <span class="caret"></span>
            </button>
            <ul class="dropdown-menu" role="menu" id = "buttonsPlace">
            </ul>

        </div>

In my js file :

for (i = 0; i < platformList.length; i++) {
        var li =  $("<li/>" , { id : "plat"+i,class : "dropdown" text : platformList[i]  } )
        //var text = document.createTextNode(platformList[i]);
        //li.appendChild(text);
        //btn.data("platform", platformList[i] );
         $("#buttonsPlace").append(li);
        console.log("hiding");
        $("#plat" + i).hide();
    }

However the menu is appearing but the menu items are not. where am i going wrong

Small part of my html code :

<div class="text-center">

        <div class="btn-group">
            <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
                Platforms <span class="caret"></span>
            </button>
            <ul class="dropdown-menu" role="menu" id = "buttonsPlace">
            </ul>

        </div>

In my js file :

for (i = 0; i < platformList.length; i++) {
        var li =  $("<li/>" , { id : "plat"+i,class : "dropdown" text : platformList[i]  } )
        //var text = document.createTextNode(platformList[i]);
        //li.appendChild(text);
        //btn.data("platform", platformList[i] );
         $("#buttonsPlace").append(li);
        console.log("hiding");
        $("#plat" + i).hide();
    }

However the menu is appearing but the menu items are not. where am i going wrong

Share Improve this question asked Jul 21, 2014 at 7:28 user3840570user3840570 511 gold badge1 silver badge6 bronze badges 0
Add a ment  | 

2 Answers 2

Reset to default 3

Try This

$(function() {
    var change = function( txt ) {
        $("#ID").append( '<li>' + txt + '</li>' );
    };
    change("this is the first change");
    change("this is the second change");
});

Demo

For Li Click

$("ul").on('click', 'li', function () {
   var id = this.id;
   //play with the id
});
$(function(){

    $('.dropdown-toggle').click(function(){

        var countRows = $('ul.dropdown-menu li').size();
        $('.dropdown-menu').append('<li>Row '+countRows+'</li>');
        countRows++;
    });

});

Here is the jsfiddle for you http://jsfiddle/alexchizhov/ncgXK/

$('#drowdown-link1').click(function(e){
   e.preventDefault();
   window.location.href = 'http://example.';
});

Here is another jsfiddle for you http://jsfiddle/alexchizhov/ncgXK/4/

本文标签: javascriptdynamically create items in drop down list in bootstrapStack Overflow