TypeError:Window.getDefaultComputedStyle的参数1未实现接口Element

时间:2014-07-28 11:19:09

标签: javascript jquery polymer

我的聚合物元素外面有以下代码(在另一种聚合物中):

        $(mainThis.shadowRoot.querySelector('#test1')).click(function(e){
            mainThis.$.testelement.openPopup();
        });

该行:

mainThis.$.testelement.openPopup();

导致错误:

TypeError: Argument 1 of Window.getDefaultComputedStyle does not implement interface Element.

openPopup - 是我在聚合物中的自定义功能" testelement"。 该错误仅出现在其他浏览器(Chrome,Safari,Opera)上的FireFox(版本31)中。如何解决?

编辑(openPopup函数):

<script type="text/javascript">
    Polymer('popup-element', {

        domReady : function() {
            var mainThis = this;
            $(this.$.popup).on('click','.closebutton', function(e){
                mainThis.closePopup();
            });
        },
        openPopup : function (){
            $(this.$.popup).show();
            return this;
        },
        closePopup : function (){
            $(this.$.popup).hide();
            return this;
        }
    });

</script>

1 个答案:

答案 0 :(得分:1)

好的,现在我可以看到。我有同样的问题。我已经解决了这个问题: 而不是:

$(this.$.popup).show();

试试这个:

this.$.popup.style.display = "block";

看来,当你从另一个聚合物元素执行它时,在聚合物元素javascript函数中使用jQuery是不可能的(仅在firefox中!)。请有人比我更聪明,以改善这个答案:)