2015-12-28 4 views
-1

Я хочу создать веб-сайт с вопросом о множественном выборе и показать результат, который будет искажать или неправильно при нажатии на правильный ответ.
Я застрял в коде, он показывает все элементы, потому что я дал одно и то же имя для всего класса.не может показать конкретный ответ с тем же именем класса.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> 
<script> 



$(document).ready(function(){ 
    $(".img1").hide(); 

    $(".show1").click(function(){ 
       $(".img1").show(); 
    }); 



}); 
</script> 

<style> 
#header { 
    background-color:black; 
    color:white; 
    text-align:center; 
    padding:5px; 
} 
#nav { 

    background-color:#eeeeee; 
    height:160px; 
    width:100px; 
    float:left; 
    padding:5px;   
} 
#section { 
    width:800px; 
    float:left; 
    padding:10px;   
} 
#footer { 
    background-color:black; 
    color:white; 
    clear:both; 
    text-align:center; 
    padding:5px;  
} 
</style> 

</head> 

<body> 

<div style="width:960px; height:80px; background-color:#3b5998"> 

<div id="header"> 
<h1>City Gallery</h1> 
</div> 

<div id="nav"> 
London<br> 
Paris<br> 
Tokyo 
</div> 

<div id="section"> 
<div> 

<table style="width:100%"> 
    <tr> 
    <td colspan="3"><p>A train running at the speed of 60 km/hr crosses a pole in 9 seconds. What is the length of the train?</p></td> 

    </tr> 
    <tr> 
    <td><a href="#" class="show1" style="text-decoration:none"><strong>A.</strong> &nbsp; 120 &nbsp;</a> <a href="#" class="img1"><img src= "images/logo/correct.png" width="14" height="14" /></a> </td> 




    <td><a href="#" class="show1" style="text-decoration:none" ><strong><strong>B.</strong> &nbsp; 180 &nbsp; 
    </a> <a href="#" class="img1"><img src= "images/logo/wrong.png" width="14" height="14" /></a> </td> 

    </tr> 
    <tr> 

    <td><a href="#" class="show1" style="text-decoration:none" ><strong>C.</strong> &nbsp; 324 &nbsp; 
    </a> <a href="#" class="img1"><img src= "images/logo/wrong.png" width="14" height="14" /></a> </td> 


    <td><a href="#" id="show1" style="text-decoration:none" ><strong>D.</strong> &nbsp; 150 &nbsp; 
    </a> <a href="#" class="img1"><img src= "images/logo/wrong.png" width="14" height="14" /></a> </td> 

    </tr> 
</table> 




<table style="width:100%"> 
    <tr> 
    <td colspan="3"><p>A train running at the speed of 60 km/hr crosses a pole in 9 seconds. What is the length of the train?</p></td> 

    </tr> 
    <tr> 
    <td> 
    <a href="#" id="show1" style="text-decoration:none"><strong>A.</strong> &nbsp; 120 &nbsp;</a> <a href="#" class="img1"><img src= "images/logo/correct.png" width="14" height="14"/></a> </td> 




    <td><a href="#" id="show1" style="text-decoration:none" ><strong><strong>B.</strong> &nbsp; 180 &nbsp; 
    </a> <a href="#" class="img1"><img src= "images/logo/wrong.png" width="14" height="14" /></a> </td> 

    </tr> 
    <tr> 

    <td><a href="#" id="show1" style="text-decoration:none" ><strong>C.</strong> &nbsp; 324 &nbsp; 
    </a> <a href="#" class="img1"><img src= "images/logo/wrong.png" width="14" height="14" /></a> </td> 


    <td><a href="#" id="show1" style="text-decoration:none" ><strong>D.</strong> &nbsp; 150 &nbsp; 
    </a> <a href="#" class="img1"><img src= "images/logo/wrong.png" width="14" height="14" /></a> </td> 

    </tr> 
</table> 
</div> 
`enter code here`</div> 
<div id="footer"> 
+0

ли вы на самом деле есть вопрос? –

+0

Вы используете идентификатор «# show1» _four_ раз. Идентификаторы должны быть уникальными = используется только один раз в документе. Измените это ... – Johannes

ответ

0

Попробуйте заменить class дублированных "show1"id с помощью .next(); также удаления дубликатов открытия <strong> теги

$(document).ready(function() { 
 
    $(".img1").hide(); 
 
    $(".show1").click(function() { 
 
    $(this).next(".img1").show(); 
 
    }); 
 
})
<head> 
 
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> 
 
    <style> 
 
    #header { 
 
     background-color: black; 
 
     color: white; 
 
     text-align: center; 
 
     padding: 5px; 
 
    } 
 
    #nav { 
 
     background-color: #eeeeee; 
 
     height: 160px; 
 
     width: 100px; 
 
     float: left; 
 
     padding: 5px; 
 
    } 
 
    #section { 
 
     width: 800px; 
 
     float: left; 
 
     padding: 10px; 
 
    } 
 
    #footer { 
 
     background-color: black; 
 
     color: white; 
 
     clear: both; 
 
     text-align: center; 
 
     padding: 5px; 
 
    } 
 
    </style> 
 

 
</head> 
 

 
<body> 
 
    <div style="width:960px; height:80px; background-color:#3b5998"> 
 
    <div id="header"> 
 
     <h1>City Gallery</h1> 
 
    </div> 
 

 
    <div id="nav"> 
 
     London 
 
     <br>Paris 
 
     <br>Tokyo 
 
    </div> 
 

 
    <div id="section"> 
 
     <div> 
 

 
     <table style="width:100%"> 
 
      <tr> 
 
      <td colspan="3"> 
 
       <p>A train running at the speed of 60 km/hr crosses a pole in 9 seconds. What is the length of the train?</p> 
 
      </td> 
 

 
      </tr> 
 
      <tr> 
 
      <td><a href="#" class="show1" style="text-decoration:none"><strong>A.</strong> &nbsp; 120 &nbsp;</a> 
 
       <a href="#" class="img1"> 
 
       <img src="http://lorempixel.com/50/50/?0" width="14" height="14" /> 
 
       </a> 
 
      </td> 
 

 

 

 

 
      <td><a href="#" class="show1" style="text-decoration:none"><strong>B.</strong> &nbsp; 180 &nbsp; 
 
    </a> 
 
       <a href="#" class="img1"> 
 
       <img src="http://lorempixel.com/50/50/?1" width="14" height="14" /> 
 
       </a> 
 
      </td> 
 

 
      </tr> 
 
      <tr> 
 

 
      <td><a href="#" class="show1" style="text-decoration:none"><strong>C.</strong> &nbsp; 324 &nbsp; 
 
    </a> 
 
       <a href="#" class="img1"> 
 
       <img src="http://lorempixel.com/50/50/?2" width="14" height="14" /> 
 
       </a> 
 
      </td> 
 

 

 
      <td><a href="#" class="show1" style="text-decoration:none"><strong>D.</strong> &nbsp; 150 &nbsp; 
 
    </a> 
 
       <a href="#" class="img1"> 
 
       <img src="http://lorempixel.com/50/50/?3" width="14" height="14" /> 
 
       </a> 
 
      </td> 
 

 
      </tr> 
 
     </table> 
 

 

 

 

 
     <table style="width:100%"> 
 
      <tr> 
 
      <td colspan="3"> 
 
       <p>A train running at the speed of 60 km/hr crosses a pole in 9 seconds. What is the length of the train?</p> 
 
      </td> 
 

 
      </tr> 
 
      <tr> 
 
      <td> 
 
       <a href="#" class="show1" style="text-decoration:none"><strong>A.</strong> &nbsp; 120 &nbsp;</a> 
 
       <a href="#" class="img1"> 
 
       <img src="http://lorempixel.com/50/50/?4" width="14" height="14" /> 
 
       </a> 
 
      </td> 
 

 
      <td><a href="#" class="show1" style="text-decoration:none"><strong>B.</strong> &nbsp; 180 &nbsp; 
 
    </a> 
 
       <a href="#" class="img1"> 
 
       <img src="http://lorempixel.com/50/50/?5" width="14" height="14" /> 
 
       </a> 
 
      </td> 
 

 
      </tr> 
 
      <tr> 
 

 
      <td><a href="#" class="show1" style="text-decoration:none"><strong>C.</strong> &nbsp; 324 &nbsp; 
 
    </a> 
 
       <a href="#" class="img1"> 
 
       <img src="http://lorempixel.com/50/50/?6" width="14" height="14" /> 
 
       </a> 
 
      </td> 
 

 

 
      <td><a href="#" class="show1" style="text-decoration:none"><strong>D.</strong> &nbsp; 150 &nbsp; 
 
    </a> 
 
       <a href="#" class="img1"> 
 
       <img src="images/logo/wrong.png" width="14" height="14" /> 
 
       </a> 
 
      </td> 
 

 
      </tr> 
 
     </table> 
 
     </div> 
 
     `enter code here`</div> 
 
    <div id="footer">

Смежные вопросы