如何在链接中添加条件以运行onclick?

时间:2019-09-26 02:16:37

标签: javascript html asp.net onclick ternary-operator

我的代码如下:

switch (methodIndex) {
    case "111":
        doAction1();
        break;
    case "110":
        doAction2();
        break;
    case "101":
        doAction3();
        break;
    case "100":
        doAction4();
        break;
    case "011":
        doAction5();
        break;
    case "010":
        doAction6();
        break;
    case "001":
        doAction7();
        break;
    case "000":
        doAction8();
        break;
    default:
        System.out.println("No action defined");
}

我要添加条件

如果<ul id="sticky-tab" class="hide-on-med-and-down"> @foreach (Sitecore.Data.Items.Item item in _stickyMenu.Children) { var popupsourceID = item.Fields[Templates.Navigable.Fields.PopUpSource].ToString(); Item popupData = null; var classTriger = string.Empty; if (!string.IsNullOrEmpty(popupsourceID)) { popupData = Sitecore.Context.Database.GetItem(new Sitecore.Data.ID(popupsourceID)); } var popupID = string.Empty; if (popupData != null) { popupDataList.Add(popupData); classTriger = "modal-trigger"; popupID = "#modal-" + popupData.ID.ToShortID().ToString(); } <li class="content accent-4 z-depth-2 @item.Fields[Templates.Navigable.Fields.CustomClass]" data-color="@item.Fields[Templates.Navigable.Fields.CustomClass]"> <a onclick="gtag('event', 'Click', { 'event_category': 'Outbound Link', 'event_action':'Click','event_label':'Live365BroadcastLaunch-ListenLive' });" class="@classTriger" href="@(popupID==string.Empty?item.LinkFieldUrl(Templates.Link.Fields.Link).ToString():popupID)"> <div class="icon"><img src="@item.ImageUrl(Templates.LinkMenuItem.Fields.IconImage)" /></div> <div class="text">@item.Fields[Templates.Navigable.Fields.NavigationTitle]</div> </a> </li> } </ul> = item.LinkFieldUrl(Templates.Link.Fields.Link).ToString(),则它将运行Make-App。否则,它不会运行onclick

我该如何解决这个问题?

0 个答案:

没有答案