مسج السيطرة على عناصر div واحدة مع الصنف ذاته (الأشقاء؟)

StackOverflow https://stackoverflow.com/questions/261572

  •  06-07-2019
  •  | 
  •  

سؤال

وأنا بناء وحدة نمطية التعليمات لموقعي وأريد أن أكون قادرة على السيطرة على العناصر واحدة على الصفحة على الرغم من أنهم جميعا لديهم نفس الفئة. وأعتقد أن هذا يأتي في إطار الأخوة وأنا لست على دراية حتى الان.

وأساسا أريد المستخدم لتكون قادرة على الضغط على شعبة السؤال ثم عند النقر عليه الجواب شعبة في نفس شعبة كما تم تعيين شعبة السؤال لإظهار (إذا كان هذا الأمر يبدو معقولا تماما!). أي مساعدة سيكون موضع تقدير كبير.

<div class="set">
<div class="question">What is the airspeed velocity of an unladen swallow?</div>
<div class="answer">Although a definitive answer would of course require further measurements, published species-wide averages of wing length and body mass, initial Strouhal estimates based on those averages and cross-species comparisons, the Lund wind tunnel study of birds flying at a range of speeds, and revised Strouhal numbers based on that study all lead me to estimate that the average cruising airspeed velocity of an unladen European Swallow is roughly 11 meters per second, or 24 miles an hour. </div>
</div>

<div class="set">
<div class="question">What is the airspeed velocity of an unladen swallow?</div>
<div class="answer">Although a definitive answer would of course require further measurements, published species-wide averages of wing length and body mass, initial Strouhal estimates based on those averages and cross-species comparisons, the Lund wind tunnel study of birds flying at a range of speeds, and revised Strouhal numbers based on that study all lead me to estimate that the average cruising airspeed velocity of an unladen European Swallow is roughly 11 meters per second, or 24 miles an hour. </div>
</div>

<div class="set">
<div class="question">What is the airspeed velocity of an unladen swallow?</div>
<div class="answer">Although a definitive answer would of course require further measurements, published species-wide averages of wing length and body mass, initial Strouhal estimates based on those averages and cross-species comparisons, the Lund wind tunnel study of birds flying at a range of speeds, and revised Strouhal numbers based on that study all lead me to estimate that the average cruising airspeed velocity of an unladen European Swallow is roughly 11 meters per second, or 24 miles an hour. </div>
</div>
هل كانت مفيدة؟

المحلول

إذا فهمت سؤالك بشكل صحيح، يجب عليك تبدأ من خلال وضع جميع الإجابات كما مخبأة في المغلق: .answer {عرض: لا شيء؛}

وبعد ذلك يمكنك استخدام مسج لإظهار الإجابة الصحيحة على الأسئلة النقر:

$(document).ready ( function () {
    $('.question').click(function() {
        $(this).next('.answer').show();
    });
});

وتحرير: يمكنك أيضا استخدام .toggle () بدلا من. تظهر () لإظهار / إخفاء

نصائح أخرى

وربما يجب عليك التحقق من هذا السؤال حيث يتم شيئا من هذا القبيل.

والأساس، وتحتاج أولا إلى معرف الإعداد لعناصر الخاص بك بحيث يمكنك تحديد العناصر واحدة داخل الطبقات مجموعة.

ويمكنك بعد ذلك إضافة معالج فوق الحدث الذي سيشكل العنصر المحدد وتظهر الإجابة المناسبة.

ويمكنك مشاهدة بناء الجملة من أجل الاستيلاء على الأشقاء في هنا .

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top