English 中文(简体)
同一条 j的多处情况
原标题:multiple instances of the same jquery script
  • 时间:2010-07-26 02:40:57
  •  标签:
  • jquery

如果说有文字,但需要在一个网页上多次使用,例如,在一厘米上,你如何这样做? 在一次试验中,一号法规有多次操作,但一则规定该文章在选择器的结尾,这些选择器将击退指挥和需要加以操纵。 它不是一种良好的工作,而造成法典的重复过多(即使它运作)。

这里的一个例子是,我在最近的一次流 over讨论中(与所附条款(主文)一起):

<script type="text/javascript">
    $(document).ready(function() {
        $( .fullTracksInner<txp:article_id /> ).hide();
        $( .tracklist<txp:article_id /> ).click(function() {
            $( .fullTracksInner<txp:article_id /> ).slideToggle( medium );
            if ($( .fullTracksInner<txp:article_id /> ).is( :hidden )) {
                $(this).text( Show Tracklist );
            } else {
                $(this).text( Hide Tracklist );
            }
        });
    });
</script>

举例来说,用同样的幻灯片在一页上 three有三种幻灯。

最佳回答

这是一项比较常见的任务,可在酒吧工作。 为了在同一个网页上为多个要素开展工作而无需独一无二的识别资料,你刚刚需要使用<代码>$(本),以确定你重新采取行动的相对内容。 我不知道你所再次看到的是什么样子,但你也许会做以下事情:

$(document).ready(function() {
 $( .fullTracksInner<txp:article_id /> ).hide();

    $( .tracklist<txp:article_id /> ).click(function() {
     $(this).children( .fullTracksInner<txp:article_id /> ).slideToggle( medium );
        if ( $(this).children( .fullTracksInner<txp:article_id /> ).is( :hidden ) ) {
            $(this).text( Show Tracklist );
        } else {
            $(this).text( Hide Tracklist );
        }
    });
});

You大概应当稍微修改你的甄选者,但我想到,$(履历和参照;txp:article_id /> > 在某些浏览器中可能窒息。

问题回答

你们可以提取重复法,以规范贾瓦文法,然后在任何地方将其称作。

<script type="text/javascript">
function performSlide(tracklist) {
    var fulltracks = $( .fullTracksInner<txp:article_id /> );

    $(fulltracks).slideToggle( medium );
    if (fulltracks).is( :hidden )) {
        changeText(tracklist,  Show Tracklist );
    } else {
        changeText(tracklist,  Hide Tracklist );
    } 
}

function changeText(textbox, text) {
    textbox.text(text);
}

$(document).ready(function() {
    var tracklist = $( .tracklist<txp:article_id /> );

    tracklist.click(function() {
        performSlide(tracklist);
    });

    $( .someRadioButton ).change(function() {
        performSlide(tracklist); 
    });
});
</script>




相关问题
getGridParam is not a function

The HTML: <a href="javascript:void(0)" id="m1">Get Selected id s</a> The Function: jQuery("#m1").click( function() { var s; s = jQuery("#list4").getGridParam( selarrrow )...

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.

jQuery cycle page with links

I am using the cycle plugin with pager functionality like this : $j( #homebox ) .cycle({ fx: fade , speed: fast , timeout: 9000, pager: #home-thumbs , ...

jquery ui dialog opens only once

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.

jConfirm with this existing code

I need help to use jConfirm with this existing code (php & Jquery & jAlert). function logout() { if (confirm("Do you really want to logout?")) window.location.href = "logout.php"; } ...

Wrap text after particular symbol with jQuery

What I m trying to do, is wrap text into div inside ll tag. It wouldn t be a problem, but I need to wrap text that appears particularly after "-" (minus) including "minus" itself. This is my html: &...