jQuery-禁用特定td的实时点击事件 [英] jQuery - Disable live click event for particular td

查看:560
本文介绍了jQuery-禁用特定td的实时点击事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一张桌子,我通过.live()将click事件分配给每一行中的每个td(id ="min")

I got a table and i assign the click event via .live() to each td (id="min") in every row

查看:

            <td id="min">
                @Html.Action("GetMinAmount", "Stock", new { id = item.FoodID })
            </td>      

控制器(显示图像或数量)

Controller (to display either image or amount)

     // Function to return min amount, if null return "-"
    public string GetMinAmount(int id)
    {
        var food = dbEntities.FOODs.Single(f => f.FoodID == id);
        string output = "";
        if (food.MinAmount == null)
        {
            output += "<img id=\"disable\" src=\"../../Content/Add_in_Images/disable.png\" alt=\"disable\" style=\"background-image: none\"/>";
        }
        else
        {
            return food.MinAmount.ToString();
        }
        return output;
    }

脚本:

       $('#min').live('click', function () { $editdialog.dialog('open'); });

但是在td中,我可以有2个条件,一个是启用"状态,其中显示了用户可以单击和编辑金额的金额.如果数量为空,将显示一个图标,用户无法对其进行任何操作.

But inside the td I can have 2 conditions, one is the "enabled" state which showing the Amount where user can click and edit the amount. If the amount is null, an icon will be displayed and user cannot do anything with it.

当前,我无法删除已禁用图片的点击处理程序.因此,即使是应该被禁用的td也是可以点击的...

Currently I cant remove the click handler for the disabled image. So even the td which suppose to be disabled is clickable also...

我不知道如何删除仅用于已禁用" td的点击处理程序.

I got no idea how can i remove the click handler for the "disabled" td only.

任何人都可以帮助???谢谢.......

Anyone can help??? Thanks.......

推荐答案

我以某种方式改变了我的控制器,使其以一种肮脏的"方式来做到这一点?

I somehow change my controller to do it in a "dirty" way i would say?

 // Function to return min amount, if null return "-"
    public string GetMinAmount(int id)
    {
        var food = dbEntities.FOODs.Single(f => f.FoodID == id);
        string output = "";
        if (food.MinAmount == null)
        {
            output += "<img class=\"disable\" src=\"../../Content/Add_in_Images/disable.png\" alt=\"disable\" style=\"background-image: none\"/>";
        }
        else
        {
            output += "<h4 class=\"edit\">" + food.MinAmount + "</h4>";
        }
        return output;
    }

只需将我的金额放入包装器中,然后将点击事件分配给仅包含金额的td ...

Just putting my amount in a wrapper and I assign the click event to the td with the amount only...

   $('.edit').live('click', function () {

关于此的任何建议?

感谢所有反馈...谢谢....

Appreciate all the feedback... Thanks....

这篇关于jQuery-禁用特定td的实时点击事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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