调用JavaScript脚本运行PageListPager MVC [英] Calling Javascript On PageListPager MVC

查看:180
本文介绍了调用JavaScript脚本运行PageListPager MVC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想下面叫提寻呼的JavaScript即PageListPager这是我的看法页

 <脚本类型=文/ JavaScript的>    (文件)。在('点击','A',函数someFunction(){
        警报(OK)
        。的document.getElementById('页面')值= CNT;
        $(#testStartedForm)提交()。
    });
< / SCRIPT>< D​​IV CLASS =pagedList>
       @ Html.PagedListPager(型号,页= GT; Url.Action(TestStarted,学生,新的{页,TestId = ViewBag.TestId,的onclick =someFunction(+网页+)}),PagedListRenderOptions。 EnableUnobtrusiveAjaxReplacing(新AjaxOptions {UpdateTargetId =成果,列举HTTPMethod =POST}))
     < / DIV>


解决方案

不,你不能这样做的(你试图通过someFunction(+网页+)来命名控制器上的参数的onclick )。你可以订阅点击&LT的事件; A> 标记。例如:

 的$(document)。在('点击','A',函数(){
  // 做一点事
});

但你应该改变文件来的选择是相关的&LT最接近的父母; A> 标签

I want to call below mention javascript on paging i.e PageListPager which is on my view page

<script type="text/javascript">

    (document).on('click', 'a', function someFunction() {
        alert("ok")
        document.getElementById('page').value = cnt;
        $("#testStartedForm").submit();
    });


</script>



<div class="pagedList">
       @Html.PagedListPager(Model, page => Url.Action("TestStarted", "Student", new { page,TestId = ViewBag.TestId,onclick="someFunction(" + page + ")" }), PagedListRenderOptions.EnableUnobtrusiveAjaxReplacing(new AjaxOptions { UpdateTargetId="results",HttpMethod="POST"}))
     </div>

解决方案

No you cant do it that way (your trying to pass "someFunction(" + page + ")" to a parameter on the controller named onclick). You could subscribe to the click event of the <a> tags. For example

$(document).on('click', 'a', function() {
  // do something
});

but you should change document to a selector which is the closest parent of the relevant <a> tags

这篇关于调用JavaScript脚本运行PageListPager MVC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆