仅在单击标签时执行perl代码<a>



我只想在单击<a>标记时执行一些perl代码,而不是每次加载.html.ep文件时都执行,而且我不知道如何执行。到目前为止,我尝试将perl代码放在href:前面

<a <% $type = $type eq 'desc' ? 'asc' : 'desc'; %>
href="<%= url_for('customer_statistics')
. "?sort_by=" . "date_begin"
. "&type=" . $type %>">

但它不起作用,因为它在每次加载页面时都在执行。我的问题是:我可以只在点击<a>标签时执行perl代码,而不使用javascript吗?

我使用第二个变量$next_type:解决了这个问题

<th><a <% $next_type = $type eq 'desc' ? 'asc' : 'desc'; %>
href="<%= url_for('customer_statistics')
. "?sort_by=" . "num_comments"
. "&type=" . $next_type %>">
<%= l('No. comments') %></a>

它比使用JS 更优雅

最新更新