0
我有以HTML格式蜇值的數據如何應用CSS和jQuery風格如何綁定菜單和子菜單使用jquery應用css?
public class Menus
{
public List<Menus> GetALL { get; set; }
public int menuId { get; set; }
public string menuName { get; set; }
public string menuURL { get; set; }
public int parentId { get; set; }
}
public class MenuModel
{
public MenuItemsEntities objEntities = new MenuItemsEntities();
public string GetMenu()
{
//Get MainMenu Menus
Menus menuobj = new Menus();
var objmenu = from menus in objEntities.MenuItems
where menus.ParentId == 0
select menus;
string strMenuBuild = string.Empty;
strMenuBuild += "<ul>";
foreach (var i in objmenu)
{
menuobj.menuName = i.ItemName;
menuobj.menuId = i.MenuItemsID;
menuobj.menuURL = i.URL;
if (i.ParentId == 0)
{
//GetSubMenu();
strMenuBuild = strMenuBuild + "<li><a href='" + menuobj.menuURL + "'>" + menuobj.menuName + "</a><ul>";
strMenuBuild += GetSubMenu(Convert.ToInt32(menuobj.menuId)) + "</ul></li>";
//strMenuBuild += "</ul></li>";
}
}
strMenuBuild += "</ul>";
return strMenuBuild;
}
public string GetSubMenu(int submenuid)
{
string strSubBuild = string.Empty;
Menus menuobj = new Menus();
var submenu= from menus in objEntities.MenuItems
where menus.ParentId == submenuid
select menus;
if (submenu.Count() > 0)
{
foreach (var sbmnu in submenu)
{
menuobj.menuURL = sbmnu.URL;
menuobj.menuName = sbmnu.ItemName;
menuobj.menuId = sbmnu.MenuItemsID;
strSubBuild = strSubBuild + "<li ><a href='" + menuobj.menuURL + "'>" + menuobj.menuName + "</a>";
var submneu1 = from menus in objEntities.MenuItems
where menus.ParentId == menuobj.menuId
select menus;
if (submneu1.Count() > 0)
{
strSubBuild += "<ul>";
strSubBuild += GetSubMenu(Convert.ToInt32(menuobj.menuId));
strSubBuild += "</ul>";
}
strSubBuild += "</li>";
}
}
return strSubBuild;
}
}
我不得不返回字符串在HTML中甲這樣的
- 菜單的Apperals
- 襯衫
- T恤衫
- H3SubMenu1
- 牛仔褲
- P1Submenu1
- P2SubMenu2
- 褲
- 運動裝
- Women'sMenu」 Apperals
- 紗麗
- 連衣裙
- 褲子
- 手機
- MobilePhones
- 片
- Memorycards
- Bluetooths
- Jewellerry
- 耳環
- 戒指
- 鏈
- KidsJwellery
,但我綁定。我想要的菜單和子菜單APPY CSS和jquery.how到申請Css和jQuery我不知道。可以任何一個幫我請..
你可以嘗試菜單樣式此鏈接:http://javascript-array.com/scripts/multi_level_drop_down_menu/?st 或這一個:http://www.noupe.com/css/100-great-css-menu-tutorials.html – Koenyn
@ koenyn ..實際上返回Html格式right.so要寫jquery函數應用值...我看到鏈接http://stackoverflow.com/questions/6688963/jquery-recursive-function-combine-nested-li-into-one ...仍然混淆如何轉換爲jquer y .. plas幫我編輯 –
好吧,如果你有正確格式的HTML,並且你知道你想使用什麼樣式,並且你想要做的就是使用jQuery將CSS類應用到你的HTML中,那很簡單。 您可以使用css選擇器來抓取jQuery對象。即獲得你的li元素,你可以使用'$(「li」)'然後添加一個css類到你將會使用'$(「li」)。addClass(「menuItem」);' – Koenyn