Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.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
Javascript 如何重新启用在ie和firefox中选择元素的功能?_Javascript_Jquery - Fatal编程技术网

Javascript 如何重新启用在ie和firefox中选择元素的功能?

Javascript 如何重新启用在ie和firefox中选择元素的功能?,javascript,jquery,Javascript,Jquery,我已使用以下脚本禁用表上的脚本高亮显示 function disableSelection(target) { if (typeof target.onselectstart != "undefined") //IE route target.onselectstart = function () { return false; }; else if (typeof target.style.MozUserSelect != "undefined") //Fire

我已使用以下脚本禁用表上的脚本高亮显示

function disableSelection(target) {
    if (typeof target.onselectstart != "undefined") //IE route
        target.onselectstart = function () { return false; };
    else if (typeof target.style.MozUserSelect != "undefined") //Firefox route
        target.style.MozUserSelect = "none";
    else //All other route (ie: Opera)
        target.onmousedown = function () { return false; };
    target.style.cursor = "default";
}
我希望能够逆转上述方法的效果,这样当用户单击td中的输入时,他们可以使用jQuery.select()方法选择所有文本

当我尝试时,我真的不明白如何扭转效果

function enableSelection(target) {
    if (typeof target.onselectstart != "undefined") //IE route
        target.onselectstart = function () { return true; };
    else if (typeof target.style.MozUserSelect != "undefined") //Firefox route
        target.style.MozUserSelect = "none";
    else //All other route (ie: Opera)
        target.onmousedown = function () { return false; };
    target.style.cursor = "default";
}

它不起作用,我在IE中发现object not found错误。希望有人能帮助我这是为了我周末必须完成的一项重要工作。

我能够在IE中使用它。你确定它与其他错误无关吗

下面是一个在IE 9中对我有用的测试页面:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
</head>
<body> 
    <div id="test">
        test test
        test test
        <br />
        test test
    </div>
    <button onclick="disableSelection(document.getElementById('test'))" value="off">off</button>
    <button onclick="enableSelection(document.getElementById('test'))" value="on">on</button>

    <script type="text/javascript">
        function enableSelection(target) {
            if (typeof target.onselectstart != "undefined") //IE route
                target.onselectstart = function () { return true; };
            else if (typeof target.style.MozUserSelect != "undefined") //Firefox route
                target.style.MozUserSelect = "none";
            else //All other route (ie: Opera)
                target.onmousedown = function () { return false; };
            target.style.cursor = "default";
        }

        function disableSelection(target) {
            if (typeof target.onselectstart != "undefined") //IE route
                target.onselectstart = function () { return false; };
            else if (typeof target.style.MozUserSelect != "undefined") //Firefox route
                target.style.MozUserSelect = "none";
            else //All other route (ie: Opera)
                target.onmousedown = function () { return false; };
            target.style.cursor = "default";
        }


    </script>
</body>
</html>

测试
测试

测试 关 在…上 功能启用选择(目标){ if(typeof target.onselectstart!=“未定义”)//IE路由 target.onselectstart=函数(){return true;}; else if(typeof target.style.mozzuserselect!=“未定义”)//Firefox路由 target.style.mozzuserselect=“无”; else//所有其他路线(即:歌剧院) target.onmousedown=函数(){return false;}; target.style.cursor=“默认”; } 功能禁用选择(目标){ if(typeof target.onselectstart!=“未定义”)//IE路由 target.onselectstart=函数(){return false;}; else if(typeof target.style.mozzuserselect!=“未定义”)//Firefox路由 target.style.mozzuserselect=“无”; else//所有其他路线(即:歌剧院) target.onmousedown=函数(){return false;}; target.style.cursor=“默认”; }
这对我有效(仅在chrome中测试)

功能启用选择(目标){ //对于IE,此代码将起作用 if(typeof target.onselectstart!=“未定义”){ target.onselectstart=函数(){ 返回true; } }

}

//For Firefox This code will work
else if(typeof target.style.MozUserSelect != "undefined") {
    target.style.MozUserSelect = "all";
}

//All other  (ie: Opera) This code will work
else {
    target.onmousedown = function() {
        return true;
    }
    target.style.cursor = "default";
}