【问题标题】:Assigning events using Jquery not working in Firefox使用 Jquery 分配事件在 Firefox 中不起作用
【发布时间】:2014-12-18 10:03:40
【问题描述】:

我引用了 jquery-1.8.3.js。

<script type="text/javascript">
function Assign()
{
    $(".evo").click(function ()
    {
    showit(this, 'dvEvent');
    });
}
$(document).ready(Assign);
function showit(caller, dv)
{
alert('has been called');
}
</script>

在 asp.net 页面上,我在 UpdatePanel 中有一个 Gridview。 GridView 中的每一行都有一个超链接(使用 NavigateUrl="#"),其 CssClass 为“evo”。

当我使用 Internet Explorer 运行页面并单击表中具有“evo”类的任何超链接(由 gridView 生成)时 - 函数 showit() 被调用并显示警报。

但在 Firefox 中,当我点击链接时什么也没有发生。

我需要做些什么才能让它在 Firefox 中运行?感谢您的帮助。

【问题讨论】:

标签: javascript jquery asp.net


【解决方案1】:

我会尝试对 javascript 代码进行以下更改,看看它是否有效,

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

    //changed code to select document first and then
    //the .evo class since the document will always exist
    //on a page. This is done just in case the .evo class
    //element was added dynamically
    $(document).on("click",".evo",function ()
    {
    showit(this, 'dvEvent');
    });
}
$(document).ready(Assign);
function showit(caller, dv)
{
alert('has been called');
}
</script>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-05-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多