Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/88.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用jquery拦截ActionLink_Jquery_Asp.net Mvc 4_Actionlink - Fatal编程技术网

如何使用jquery拦截ActionLink

如何使用jquery拦截ActionLink,jquery,asp.net-mvc-4,actionlink,Jquery,Asp.net Mvc 4,Actionlink,我想从隐藏字段向ActionLink添加参数。我找到了解释它的答案,但对我来说不起作用,因为它直接进入控制器操作,而不解析jquery代码 @Html.ActionLink(CommonResource.Delete, "PayrollPeriodDelete", "CodeTable", null, new { @id = "sortlink", @class = "btn btn-success" }) &l

我想从隐藏字段向ActionLink添加参数。我找到了解释它的答案,但对我来说不起作用,因为它直接进入控制器操作,而不解析jquery代码

 @Html.ActionLink(CommonResource.Delete, "PayrollPeriodDelete", "CodeTable", null, new { @id = "sortlink", @class = "btn btn-success" })

<script type="text/javascript">
        $(function () {

            $('#PayrollPeriodSearch_FromDate').datepicker();
               
            $('#PayrollPeriodSearch_ToDate').datepicker();
        });
           
        $("#sortlink").click(function()
        {
            alert("works");
            var $lat = $("#hiddencode").val();
            $(this).attr("href", $(this).attr("href") + "?id=" + $lat);
        });

    </script>
@Html.ActionLink(CommonResource.Delete,“PayrollPeriodDelete”,“CodeTable”,null,新的{@id=“sortlink”,@class=“btn btn success”})
$(函数(){
$(“#薪资周期搜索_FromDate”).datepicker();
$('#PayrollPeriodSearch_ToDate').datepicker();
});
$(“#sortlink”)。单击(函数()
{
警惕(“工作”);
var$lat=$(“#hiddencode”).val();
$(this.attr(“href”),$(this.attr(“href”)+“?id=“+$lat”);
});
我可以告诉你我的jquery是有效的,因为上面的函数运行得很好。 请提供帮助。

您需要使用指定在DOM完全加载时必须执行函数:

<script type="text/javascript">        
    $(document).ready(function () {

      $("#sortlink").click(function()
            {
                alert("works");
                var $lat = $("#hiddencode").val();
                $(this).attr("href", $(this).attr("href") + "?id=" + $lat);
            });

    }
 </script>

$(文档).ready(函数(){
$(“#sortlink”)。单击(函数()
{
警惕(“工作”);
var$lat=$(“#hiddencode”).val();
$(this.attr(“href”),$(this.attr(“href”)+“?id=“+$lat”);
});
}
试试这个

$(document).on('click','#sortlink',function(ev)
{
    ev.preventDefualt(); // this will disable default action of action link...
    alert("works");
    var $lat = $("#hiddencode").val();
    window.location =  $(this).attr("href") + "?id=" + $lat;
});