Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/73.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 如何在$().css内传递event.currentTarget.id?_Javascript_Jquery - Fatal编程技术网

Javascript 如何在$().css内传递event.currentTarget.id?

Javascript 如何在$().css内传递event.currentTarget.id?,javascript,jquery,Javascript,Jquery,此对象的目的是在单击div时显示一个弹出窗口。在弹出窗口中,我希望显示单击的div的css属性。我的问题是如何将current.target.id事件放入此行$container.cssthis.css;它将替换容器,以便为单击的每个元素检索不同的值 提前谢谢 $(function () { function popup(){ var self = this; this.identifier; this.popupStatus =

此对象的目的是在单击div时显示一个弹出窗口。在弹出窗口中,我希望显示单击的div的css属性。我的问题是如何将current.target.id事件放入此行$container.cssthis.css;它将替换容器,以便为单击的每个元素检索不同的值

提前谢谢

    $(function () {
    function popup(){
        var self = this;
        this.identifier;
        this.popupStatus = 0;
        this.css = ["width", "height", "color", "background-color"];

            $("#container > *").on('click', ':not(#popup)', function (e) 
            {
                if(event.target.id!=='backgroundPopup')
                {
                    e.stopPropagation()
                    self.centerPopup();
                    self.loadPopup();
                    self.cssAttr(); 
                }
            });

            $("#backgroundPopup").click(function()
            {
                console.log('backgroundPopup');
                self.disablePopup();
            });     

            $(document).keypress(function(e)
            {
                if(e.keyCode==27 && popupStatus==1)
                {
                    self.disablePopup();
                }
            });

          this.cssAttr = function (e){

            var html = ["Adjust the settings:"];
            //problem
            var styleProps = $("#container").css(this.css);
            console.log(styleProps);

            $.each( styleProps, function( prop, value ) {
                html.push( prop + ": " + value );
            });

            $( "#result" ).html( html.join( "<br>" ) );
            }


          this.loadPopup = function (){
            if(this.popupStatus==0)
            {
                console.log('loadPopup');
                $("#backgroundPopup").css(
                {
                    "opacity": "0.7"
                });
                $("#backgroundPopup").fadeIn("slow");
                $("#popupContact").fadeIn("slow");

            this.popupStatus = 1;
            }
        }

        this.disablePopup = function (){
            if(this.popupStatus==1)
            {
                console.log('disablePopup');
                $("#backgroundPopup").fadeOut("slow");
                $("#popupContact").fadeOut("slow");
                this.popupStatus = 0;
            }
        }

        this.centerPopup = function (){
            console.log('centerPopup');
            var windowWidth = document.documentElement.clientWidth;
            var windowHeight = document.documentElement.clientHeight;
            var popupHeight = $("#popupContact").height();
            var popupWidth = $("#popupContact").width();

            $("#popupContact").css(
            {
                "position": "absolute",
                "top": windowHeight/2-popupHeight/2,
                "left": windowWidth/2-popupWidth/2
            });

            $("#backgroundPopup").css(
            {
                "height": windowHeight
            });     
        }
    }
    var popup = new popup();
});

$+event.currentTarget.id?为什么要这样做而不是$event.currentTarget?当我这样做时,我什么也得不到您没有将事件传递给函数。是的,我这样做了,将事件作为“e”传递