首页 > 解决方案 > ASP.NET-MVC/Datatables.net 中的按钮无法工作

问题描述

我有点困惑,因为 google chrome 浏览器没有显示语法错误。该按钮已呈现但不起作用。

"render": function () {
     return "<a class='btn btn-outline-dark btn-sm' onclick= location.href = '@Url.Action("InterfaceRuntime", "Interface")'><i class='fas fa-play-circle'></i> Run</a>";
},

编辑:

感谢好的建议,我尝试了转义字符,它对我来说非常好。

"render": function () {
    return "<a class='btn btn-outline-dark btn-sm' onclick= \" location.href = '@Url.Action("InterfaceRuntime", "Interface")'\"><i class='fas fa-play-circle'></i> Run</a>"; 
},

标签: jqueryasp.net-mvcdatatables

解决方案


您可以尝试在 onclick 代码周围添加引号,如下例所示:

"render": function () {
    return "<a class='btn btn-outline-dark btn-sm' onclick=\"location.href = '@Url.Action("InterfaceRuntime", "Interface")'\""><i class='fas fa-play-circle'></i> Run</a>";
},

如果这不能解决问题,请打开 chrome 开发者控制台并查看是否有任何错误。


推荐阅读