Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/393.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/71.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 传递e参数,jQuery_Javascript_Jquery_Javascript Events - Fatal编程技术网

Javascript 传递e参数,jQuery

Javascript 传递e参数,jQuery,javascript,jquery,javascript-events,Javascript,Jquery,Javascript Events,我的文档中已准备好以下代码: $('a').click(function(e) { e.preventDefault(); var $this = $(this); var horizontalPadding = 30; var verticalPadding = 30; $('<iframe id="externalSite" class="externalSite" src="' + this.hr

我的文档中已准备好以下代码:

    $('a').click(function(e) {
        e.preventDefault();
        var $this = $(this);
        var horizontalPadding = 30;
        var verticalPadding = 30;
        $('<iframe id="externalSite" class="externalSite" src="' + this.href + '" />').dialog({
            title: ($this.attr('title')) ? $this.attr('title') : 'External Site',
            autoOpen: true,
            width: 800,
            height: 500,
            modal: true,
            resizable: true,
            autoResize: true,
            overlay: {
                opacity: 0.5,
                background: "black"
            }
        }).width(800 - horizontalPadding).height(500 - verticalPadding);            
    });
但是如何传递e参数呢?

函数a函数(e){
function aFunction(e) {
    e.preventDefault();
    var $this = $(this);
    var horizontalPadding = 30;
    var verticalPadding = 30;
    $('<iframe id="externalSite" class="externalSite" src="' + this.href + '" />').dialog({
        title: ($this.attr('title')) ? $this.attr('title') : 'External Site',
        autoOpen: true,
        width: 800,
        height: 500,
        modal: true,
        resizable: true,
        autoResize: true,
        overlay: {
            opacity: 0.5,
            background: "black"
        }
    }).width(800 - horizontalPadding).height(500 - verticalPadding);            
}

$('a').click(aFunction);
e、 预防默认值(); var$this=$(this); var水平填充=30; 垂直填充变量=30; $('')。对话框({ 标题:($this.attr('title')?$this.attr('title'):'External Site', 自动打开:对, 宽度:800, 身高:500, 莫代尔:是的, 可调整大小:正确, 自动调整大小:正确, 覆盖:{ 不透明度:0.5, 背景:“黑色” } }).宽度(800-水平填充)。高度(500-垂直填充); } $('a')。单击(函数);
jQuery会将“e”传递给您提供的函数,但您必须传递它而不带括号,因此您传递的是函数对象,而不是函数调用的结果。

执行以下操作:

function aFunction(e) { ... }
$('a').click(aFunction);
事件参数将自动传递

$('a').click();

$('a').click();
$('a').trigger('click');