1

コードは次のとおりです:http: //jsfiddle.net/t2nite/KCY8g/

SHOWボタンの下にあるボタンを取得しようとしているのHIDE/SHOW ALLは、1つのボタンを押すと、そのテキストが表示され、他のテキストは非表示になるということです。

このコードを使用しましたが、いずれかのボタンで[表示]をクリックするとすぐに表示および非表示になります。

$(".show").click(function() {
   $(this).parent().find("p").show(200);
   $("p").not(this).hide(200);
});​

ヘルプ。

4

7 に答える 7

3

あなたの問題はthis、ショー機能では<p>ボタンではなかったということでした。

$(".show").click(function() {
    var $thisP = $(this).parent().find("p")
    $thisP.show(200);
    $("p").not($thisP).hide(200);
});​

http://jsfiddle.net/KCY8g/11/

于 2012-10-17T19:03:00.457 に答える
2

jsFiddleデモ

基本的に、現在の領域以外のすべての「itsawrapp」領域を非表示にします。

$(".show").click(function() {
    var _p = $(this).parent().find('p');
    // maybe even do: $(this).closest('.itsawrap').find('p');
    // (if you ever think you'll wrap any of these things in other divs/etc

    _p.show(200);
    $('.itsawrap p').not(_p).hide();
});​
于 2012-10-17T19:02:18.163 に答える
1

表示コードを次のように変更します。

$(".show").click(function() {
    var container = $(this).closest(".itsawrap");
    $(".itsawrap").not(container).find("p").hide(200);
    container.find("p").show(200);
});​

ここでの作業デモ:http://jsfiddle.net/jfriend00/6ypRz/

これはコンテナレベルで機能するため、目的のコンテナを操作できます。

于 2012-10-17T19:02:10.880 に答える
0

間違いは親の「this」がボタンなので、$( "p")。not(this).hide(200); あなたのボタンを除いてすべてのpを言います、それはまだすべてのpです。

$(".show").click(function() {
     var parent = $(this).parent();
     $(".itsawrap").not(parent).find('p').hide(200);
     parent.find('p').show(200);
});​

http://jsfiddle.net/renekoch/KCY8g/17/

于 2012-10-17T19:12:21.223 に答える
0

このような?

$("#btn").click(function() {
    var oneshow = false;
    $(".para2, .para3, .para4").each(function() {
        if ($(this).is(":visible")) {
            oneshow = true;
        }
    });
    if (oneshow == true) {
        $(".para2, .para3, .para4").hide(200);
    } else {
        $(".para2, .para3, .para4").show(200);
    }
});

$(".hide").click(function() {
    $(this).parent().find("p").hide(200);
});

$(".show").click(function() {
    var p = $(this).parent().find("p");
    $(p).show(200);
    $(parent).not(p).hide(200);
});​
于 2012-10-17T19:03:17.383 に答える
0

問題はにありthisます。

$(".show").click(function() {
    var p = $(this).parent().find("p");
    p.show(200);
    $("p").not(p).hide(200);
});​
于 2012-10-17T19:06:59.390 に答える
0

最も短い方法の1つ:

$(".show").click(function(e) {
    $("p").not($(this).parent().find("p").show(200)).hide(200);
});

jsfiddle

于 2012-10-17T19:08:06.840 に答える