Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/22.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 nt正在由函数执行操作。因此,在本例中,匿名函数是附加到document的事件处理程序,因此this是document@periklis:在jQuery中,this始终指代将处理程序绑定到的元素。一般来说,this如果不显式地设置它,就永远不会引用函数本身_Javascript_Jquery - Fatal编程技术网

Javascript nt正在由函数执行操作。因此,在本例中,匿名函数是附加到document的事件处理程序,因此this是document@periklis:在jQuery中,this始终指代将处理程序绑定到的元素。一般来说,this如果不显式地设置它,就永远不会引用函数本身

Javascript nt正在由函数执行操作。因此,在本例中,匿名函数是附加到document的事件处理程序,因此this是document@periklis:在jQuery中,this始终指代将处理程序绑定到的元素。一般来说,this如果不显式地设置它,就永远不会引用函数本身,javascript,jquery,Javascript,Jquery,nt正在由函数执行操作。因此,在本例中,匿名函数是附加到document的事件处理程序,因此this是document@periklis:在jQuery中,this始终指代将处理程序绑定到的元素。一般来说,this如果不显式地设置它,就永远不会引用函数本身,也就是说,您必须使用func.call(func)调用函数;我认为这是指匿名函数,而不是文档itself@periklis:一个快速的谷歌出现了,它可能会比我解释得更好。本质上,尽管这个是指函数所作用的任何dom元素。因此,在本例中,匿名函数


nt正在由函数执行操作。因此,在本例中,匿名函数是附加到
document
的事件处理程序,因此
this
document
@periklis:在jQuery中,
this
始终指代将处理程序绑定到的元素。一般来说,
this
如果不显式地设置它,就永远不会引用函数本身,也就是说,您必须使用
func.call(func)
调用函数;我认为这是指匿名函数,而不是文档itself@periklis:一个快速的谷歌出现了,它可能会比我解释得更好。本质上,尽管
这个
是指函数所作用的任何dom元素。因此,在本例中,匿名函数是附加到
document
的事件处理程序,因此
this
document
@periklis:在jQuery中,
this
始终指代将处理程序绑定到的元素。通常,
如果不显式设置,则此
从不引用函数本身,即,必须使用
func.call(func)
调用函数。
<button id = "element_id" class = "myclass">Click me</button>
<script>
    $(document).ready(function() {
        this.myfunc = function() {
            console.log('Hello world');
        }
        this.myfunc();
        $('#element_id').select('.myclass').bind('click', function() {
            this.myfunc(); //Obviously this doesn't work
        });
    });
</script>​
<button id = "element_id" class = "myclass">Click me</button>
<script>
    $(document).ready(function() {
        this.myfunc = function() {
            console.log('Hello world');
        }
        this.myfunc();
            var that = this;
        $('#element_id').select('.myclass').bind('click', function() {
            that.myfunc(); //Obviously this DOES work :)
        });
    });
</script>​
$(document).ready(function() {
    var that = this;
    that.myfunc = function() {
        console.log('Hello world');
    }
    that.myfunc();
    $('#element_id').select('.myclass').bind('click', function() {
        that.myfunc();
    });
});
<button id = "element_id" class = "myclass">Click me</button> 
<script> 
    $(document).ready(function() { 
        var myfunc = function() { 
            console.log('Hello world'); 
        } 
        myfunc(); 
        $('#element_id').select('.myclass').bind('click', function() { 
            myfunc(); // works!
        }); 
    }); 
</script>​ 
<button id = "element_id" class = "myclass">Click me</button> 
<script> 
    $(document).ready(function() { 
        // storing reference to $(document) in local variable
        var that = this;
        // adding myfunc on to the document object
        that.myfunc = function() { 
            console.log('Hello world'); 
        } 
        that.myfunc(); 
        $('#element_id').select('.myclass').bind('click', function() { 
            that.myfunc(); // works!
        }); 
    }); 
</script>​ 
$('#element_id').select('.myclass').bind('click', $.proxy(function() {
    this.myfunc();
}, this));
 $(document).ready(function() {
        this.myfunc = function() {
            alert('Hello world');
        };
     var otherfunc = function() {
            alert('Hi world');
        };
     $('.cv1').click(document.myfunc);
     $('.cv2').click(otherfunc);
 });