关键字“this”Inside If语句在事件中

时间:2023-01-05 00:01:45

I have onkeypress event and I want to manipulate element this. I also have if statement in the event function. The problem is that the keyword this is different inside the if statement block. Is it normal to be like this. What explanation do you have?

我有onkeypress事件,我想操纵元素。我在事件函数中也有if语句。问题是if语句块中的关键字是不同的。像这样是正常的。你有什么解释?

example:

$(o).find('input[name=numeric]').keypress(
    function (e) {
        var a = this; // the real object element which activate the trigger
        if (e.keyCode == 13) {
            var b = this; //here "this" is different object 
        }
        else
            window.ncb.helper.validator.numeric(e);
    }
);

1 个解决方案

#1


0  

I found the problem. At the start of the if statement all is fine and visible. After that I replace html content which this lives inside of the old replaced content. Thank you anyway.

我发现了问题。在if语句的开头,一切都很好并且可见。之后,我替换了旧的替换内容中的html内容。还是非常感谢。

#1


0  

I found the problem. At the start of the if statement all is fine and visible. After that I replace html content which this lives inside of the old replaced content. Thank you anyway.

我发现了问题。在if语句的开头,一切都很好并且可见。之后,我替换了旧的替换内容中的html内容。还是非常感谢。