English 中文(简体)
环绕 j子和变数
原标题:Playing around with jQuery objects and variables
    $( div#Settings ul li ).click(function () {
        var url, template;
        var self = $(this);
        if (!$(self).hasClass( selected )) {
            var ContextMenu = CreateContext($(self));
            var id = $(self).attr( id );

......

function CreateContext(item) {
        var ContextMenu = $( div#ContextMenu );
        if (!$(ContextMenu).length) {
            $( <div id="ContextMenu"></div> ).appendTo( body );
            CreateContext(item);
        }
        $(ContextMenu).slideUp(150,  swing , function () {
            $(ContextMenu).insertAfter(item);
        });
        $(item).addClass( selected ).siblings().removeClass( selected );
        return $(ContextMenu);
    }

关于第1次查询<代码>CreateContext(项目),我不能在后面使用<代码>ContextMenu。 然而,如果两度打造《宪法》文本,所有东西都会被罚款。 我第一次在iconsole.log(ContextMenu)上看到一个不确定的变量。 第二次正确获取物体。 我如何确定这一点? 感谢。

最佳回答

由于<代码>div#ContextMenu,t 第一次出现你称之为“创造背景”。 事实上,你的职能可以发现这种情况,然后造成这种情况。 但是,在创立后,你不把<代码>ContextMenu的价值列入你的职责范围,因此该职能的其余部分没有适当运作。

Here s what I would suggest:

function CreateContext(item) {
    var ContextMenu = $( #ContextMenu );
    if (!ContextMenu.length) {
        ContextMenu = $( <div id="ContextMenu"></div> );
        ContextMenu.appendTo( body );
    }
    ContextMenu.slideUp(150,  swing , function () {
        ContextMenu.insertAfter(item);
    });
    $(item).addClass( selected ).siblings().removeClass( selected );
    return ContextMenu;
}

请注意,一旦<代码>ContextMenu 成为j Query Object,你就不必在上面填上$(>>,因为该编码已经带有 j子。

问题回答

要求把 j格指标从你的职能中删除。 由于你宣布变数为 j,我不认为你需要把变数确定为你职务的 j目标。





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签