Is it possible to interpolate my angle bracket, percent, equals <%= %> syntax in external javascript files?

后端 未结 4 1400
一生所求
一生所求 2021-02-09 23:31

Often times when mixing jQuery with asp.net I need to use asp .net angle bracket percent, <% %>, syntax within a jQuery selector.

If I would like to separate the Jav

4条回答
  •  广开言路
    2021-02-10 00:03

    No, you'll need to refactor your JavaScript to accept that information as parameters.

    So, instead of

    jQuery('#<%=MainPanel.ClientId%>').hide('slow');
    

    do something like this:

    function hidePanel(panelId) {
            jQuery('#' + panelId).hide('slow');
    }
    

    which you can call from your page with

    hidePanel('<%=MainPanel.ClientId%>');
    

提交回复
热议问题