Sunday, 15 September 2013

javascript - Asp.net bootstrap dropdown menu - selecting an item -


I have a ASP.NET project that uses bootstrap control I have the following bootstrap dropdown menu The programmatic pulls from the database.

However, when I click on the menu and select an item, then I need that item in the dropdown box clearly. Instead, when an item is clicked, there is nothing different from the dropdown menu.

  & lt; Div class = "btn-group" & gt; & Lt; Button type = "button" class = "btn btn-default dropdown-toggle" id = "merchant list" data-toggle = "dropdown" aria-expanded = "false" & gt; Select Merchant & lt; Span class = "caret"> gt; & Lt; / Span & gt; & Lt; / Button & gt; & Lt; Ul class = "dropdown-menu" roll = "menu" field-labeled = "merchant list" id = "myList" runat = "server" & gt; & Lt; ASP: literal runat = "server" id = "merchantdumpdown" & gt; & Lt; / Asp: literal & gt; & Lt; / Ul & gt; & Lt; / Div & gt;  

I think some kind of javascript is required to set whatever item is selected in the dropdown menu but I'm not sure how to do this.

I have tried:

  $ ("# myList li a") Click (function () {alert ('clicked'); var selText = $ (this) .text (); $ (this) .parents ('.btn-group'). ('.downdown-toggle' ) .HTML (seltext + '& lt; span class = "carat"> ;);});  

Also tried:

  $ ('# myList li a'). ('Click', function () {$ ('# merchantList') .val ($ (this) .text ());});  

But this is never called. any idea? It would be better if I can do it in the back code as I like to work back there.

Correct me if I am misunderstanding what you want to do, but you do not have that item Find what they chose and set their CSS class = "active". To find out that the existing items that they select match up to the current page, there are several techniques using the URL.

Try something like this on your master page:

  var url = window.location; $ ('Ul.nav a [href =' '+ url +' "] '). Parent (). AddClass (' active ');  

No comments:

Post a Comment