日期:2014-05-17  浏览次数:20443 次

JQUERY事件解绑问题
function setAllReadOnly(value) {
            if (value == true) {
                jQuery("span").live("mousemove", function () { this.setCapture(); }).live("mouseout", function () { this.releaseCapture(); }).live("focus", function () { this.blur(); }).live("before", function () { return false; });
            } else if (value == false) {
                jQuery("span").unbind("mousemove");
                jQuery("span").unbind("mouseout");
                jQuery("span").unbind("focus");
                jQuery("span").unbind("before");
            }
        }
代码如上,我想做的是 根据条件对于页面中的<span>进行事件的绑定与解绑,为了让<span>中的控件达到只读效果。现在添加事件后能达到只读效果,但我想解除绑定事件的时候,我发现unbind()执行了,但貌似没效果。新手第一次接触jquery,还有大家怎么解决控件只读的,我搜到的方法就是用span包围着。

------解决方案--------------------
事件的未绑定时候。最初是undefined。
给予绑定后。就成了function
你把值改回undefined
例如  ......("mousemove", undefined);