Latest web development tutorials

jQuery.globalEval () method

jQuery Misc Methods jQuery Misc Methods

Examples

Execute scripts in the global context

var name = "global variables"; $ (function () { function test () { var name = "Local variables"; alert (name); // local variable eval ( "Alert (name);" ); // Local variable $. GlobalEval ( "Alert (name);" ); // Global variables } test ();})

try it"

Definition and Usage

jQuery.globalEval () function is used globally execute a piece of JavaScript code.

Tip: The role of the function of the conventional JavaScript eval () function is similar. The difference is that the scope jQuery.globalEval () to execute code as a global scope.


grammar

$.globalEval( code )

参数 描述
code String类型 指定的需要运行的JavaScript代码字符串。


jQuery Misc Methods jQuery Misc Methods