0

我想要一个包含数据库中单词及其含义的表,在另一列中,我想为每一行设置复选框,该用户将检查它们并显示他/她知道的单词。在这种情况下我有两个问题:1-我如何隐藏第一个含义,然后单击显示含义可见它们?2-如何设置复选框?到目前为止我有这个代码,但它不起作用,如果可以的话请帮助我

<script type="text/javascript">
        function ShowMeanings(){
        document.getElementsByClassName('hiding').item(0).style.visiblility = 'visible';
        }
</script>
<?php
  $con = mysql_connect("localhost", "root", "")
  or die(mysql_error());   
  if (!$con) { 
                                        die('Could not connect to MySQL: ' . mysql_error()); 
                                    } 
                                    mysql_select_db("project", $con)
                                    or die(mysql_error());
                                    $result = mysql_query("select * from words");
                                    echo "<table border='1'>
                                        <tr>
                                        <th>word</th>
                                        <th>meaning</th>
                                        <th>check</th>
                                        </tr>";
                                    while($row = mysql_fetch_array($result))
                                      {
                                      echo "<tr>";
                                      echo "<td>" . $row['word'] . "</td>";
                                      echo "<td>";
                                      echo "<div";
                                      echo "class='hiding' style='visibility:hidden'>" . $row['meaninig'];
                                      echo "</div>";
                                      echo "</td>";
                                      echo "<td>";
                                      echo "<input";
                                      echo "type= 'checkbox' name = 'checkbox' id = 'checkbox' value = '' />";
                                      echo "</td>";
                                      echo "</tr>";
                                      }
                                      echo "</table>";
                                      mysql_close($con);                                                                                   
                                ?>

                                </div>
                                <button onclick="ShowMeanings()">showmeaning</button>
4

2 回答 2

0

隐藏建议:

 echo "class='hiding' style='display:none'>" . $row['meaninig'];

显示含义:

//for Jquery

<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script type="text/javascript">
        function ShowMeanings(){
           $('.hiding').shoW();
        }
</script>

或者

 //for plain old javascript
    <script type="text/javascript">
                function ShowMeanings(){
                  document.getElementsByClassName('hiding').style.visibility = 'visible';
                }
        </script>

您的代码已编辑:

<html><head>
 <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script type="text/javascript">
        function ShowMeanings(){
           $('.hiding').shoW();
        }
</script>
</head>
<body>
<?php
  $con = mysql_connect("localhost", "root", "")
  or die(mysql_error());   
  if (!$con) { 
                                        die('Could not connect to MySQL: ' . mysql_error()); 
                                    } 
                                    mysql_select_db("project", $con)
                                    or die(mysql_error());
                                    $result = mysql_query("select * from words");
                                    echo "<table border='1'>
                                        <tr>
                                        <th>word</th>
                                        <th>meaning</th>
                                        <th>check</th>
                                        </tr>";
                                    while($row = mysql_fetch_array($result))
                                      {
                                      echo "<tr>";
                                      echo "<td>" . $row['word'] . "</td>";
                                      echo "<td>";
                                      echo "<div";
                                      echo "class='hiding' style='display:none'>" . $row['meaninig'];
                                      echo "</div>";
                                      echo "</td>";
                                      echo "<td>";
                                      echo "<input";
                                      echo "type= 'checkbox' name = 'checkbox' id = 'checkbox' value = '' />";
                                      echo "</td>";
                                      echo "</tr>";
                                      }
                                      echo "</table>";
                                      mysql_close($con);                                                                                   
                                ?>

                                </div>
                                <button onclick="ShowMeanings()">showmeaning</button>
    </body>
于 2013-10-04T20:59:37.053 回答
0

getElementByClassName是一个不存在的功能。你的意思是getElementsByClassName,它会返回一个元素列表,所以你需要选择一个。

document.getElementsByClassName('hiding').item(0).style.visibility = 'visible';

于 2013-10-04T21:01:17.537 回答