javascript OO方式 - IE上的权限被拒绝错误

时间:2011-03-10 16:47:20

标签: javascript

我正在尝试下面的一些javascript:

var obj = {
    resetCss: function(){
        $("#canvas > div").click{function(){
             val = $(this).attr("id"); //I get the expected value
             obj.setCss(val);
         });
    },
    setCss: function(inp){
       alert (inp);
    },
    getCss: function(){

    }
};

标记:


    <div id="canvas">
    <div id="can1">Canvas 1</div>
    <div id="can2">Canvas 2</div>
    <div id="can3">Canvas 3</div>
    <div id="can4">Canvas 4</div>
    <div id="can5">Canvas 5</div>
    </div>

这个适用于FF,Chrome,Safari等。只有在IE浏览器上,当脚本命中“obj.setCss(val);”时我收到错误“权限被拒绝”,脚本执行终止。有人可以帮帮我吗?

谢谢, →

2 个答案:

答案 0 :(得分:0)

你有一个{而不是(在resetCss函数中。见下文。这可能在其他浏览器中被忽略但不是IE

var obj = {
    resetCss: function(){
        $("#id").click(function(){ // <---- Note the ( rather than {
           val = $(this).val(); //I get the expected value
           obj.setCss(val);
         });
    },
    setCss: function(inp){
        //some code here
       alert (inp);
    },
    getCss: function(){

    }
};

答案 1 :(得分:0)

var obj = {
    resetCss: function(){
        $("#canvas > div").click{function(){ //I think your code wrong here
             val = $(this).attr("id"); //I get the expected value
             obj.setCss(val);
         });
    },
    setCss: function(inp){
       alert (inp);
    },
    getCss: function(){

    }
};

应该改为

var obj = {
    resetCss: function(){
        $("#canvas > div").click(function(){ //Change { to (
             val = $(this).attr("id"); //I get the expected value
             obj.setCss(val);
         });
    },
    setCss: function(inp){
       alert (inp);
    },
    getCss: function(){

    }
};