0

JAVASCRIPT

function ShowContent(id) {
if(id.length < 1) { return; }
document.getElementById(id).style.display = "block";
}

PHP

$test = mysql_query('SELECT userid,testid,testname FROM test_table WHERE userid = 9 ORDER BY name');
TestName : <select>
             while($row=mysql_fetch_array($test))
             {
                $testname = $row['testname']; 
                $testid   = $row['testid'];
                echo '<option value='.$testid.'>'.$testname.'</option>
             }
           </select>
   echo '<div id="testid" style="display:none;">
      echo '<table>
             <tr><th>USERID</th</tr>
             <tr><th>TESTNAME</th></tr> 
             <tr><th>MARKS</th></tr>
      publishtest = mysql_query('SELECT id,userid,publishtest,marks FROM publish_table WHERE userid= 9 GROUP BY id');
      while($row=mysql_fetch_array($publishtest))
      {
        $userid = $row['userid'];
        $testid = $row['id']; /*This is test id*/
        $testname = $row['publishtest']; /* This is test name*/
        $marks = $row['marks'];
        echo '<tr><td>'.$userid.'</td>
                <td>'.testid.'</td>
                <td>'.testname.'</td>
                <td>'.$marks.'</td>
            </tr> 
      }
        echo '</table>';
        echo '</div>';

当我从选择标签中选择测试时,我需要显示该 testid 的 div。我想要javascript,jquery

4

1 回答 1

0

你可以试试这个:

JavaScript

$('#showDivSelect').change(function (e) {
    var divId = $(this).children('option:selected').val();
    $('#' + divId).css('display', 'block');
});​

HTML

<select id="showDivSelect">
<option id="o1">Div1</option>
<option id="o2">Div2</option>
</select>
<div id="Div1"></div>
<div id="Div2"></div>​

CSS

#Div1 {
    width: 30px;
    height: 30px;
    background-color: red;        
    display: none;
}
#Div2 {
    width: 30px;
    height: 30px;
    background-color: blue;
    display: none;    
}​

这是工作示例:http: //jsfiddle.net/ePSDu/

于 2012-08-09T06:37:35.530 回答