【发布时间】:2018-08-07 10:07:58
【问题描述】:
所以我有这个代码:
<?php
$mysql_host='localhost';
$mysql_user='root';
$mysql_password="CAN'T KNOW MY PASWORD!!!1!";
mysql_connect($mysql_host,$mysql_user,$mysql_password);
@mysql_select_db('galaxall');
?>
<style>
.clap{
background-color:red;
}
</style>
<p style="background-color:rgb(2,2,2)">
<div style="background-color:rgb(250,250,250);padding-bottom:3%;margin-right:20%">
<?php
$hello='hello everybody!!! I\'m d boss!';
$img='<img src="b5.jpg">';
$query="SELECT * FROM `comments` ";
$results = mysql_num_rows($query);
echo $results;
if($is_query_run=mysql_query($query) )
{
$results = mysql_num_rows($is_query_run);
echo "Number of comments:<font style='font-weight:bold;'>$results".'<p style="font-weight:bold;" onclick="alert("hello")">'.'</font>';
while($query_execute=mysql_fetch_assoc($is_query_run) )
{
echo $query_execute ['Comment'].'<br>'.'<br>'.'<br>'."<a href='' class='clap'>.<img src='clap4.png' width='3%' height='3%'>.'&npsp;'.'&npsp;'.'&npsp;'.'&npsp;'.'&npsp;'
.'Respond'</a>".'<p style="background-color:white;padding-bottom:1%;padding-left:3.5%;padding-top:1%;margin-left:0%;border:1px solid grey;border-radius:5%;box-shadow:2px 2px 2px #999;margin-right:25%; id="comment" >';
}
}
else
{
echo"Sorry, something went wrong...";
}
?>
</p>
<script>
var d = document.getElementsByClassName("clap");
var c = document.getElementById("comment");
function mouseOver() {
d.style.backgroundColor = "red";
}
function mouseOut() {
d.style.backgroundColor = "blue";
}
c.onmouseover = mouseOver();
c.onmouseout = mouseOut();
发生的情况是,它选择了称为注释的行的所有项目,然后美化了每个 cmets(每行 cmets 中的项目),并且每个 cmets 上都会出现一个图像(喜欢和不喜欢图标)一切都很好除了我不希望在鼠标悬停在带有 id="comment" 的评论段落上之前显示图像。但是发生的情况是我立即加载页面,cmets 已经突出显示,这是我想要在何时发生的事情鼠标悬停在“cmets”段落上,当我尝试将鼠标悬停在 cmets 上并“取消悬停(如果有这样的词:-))”时,它不会变成蓝色,但根据我的代码,它应该变成蓝色onmouseout 和红色onmouseover。我检查了我的浏览器(chrome)的控制台,上面写着
10:45:19.526 comments_gxx58.php:50 Uncaught TypeError: Cannot set property 'backgroundColor' of undefined
at mouseOver (comments_gxx58.php:50)
at comments_gxx58.php:60
In 不知道那是什么意思....
注意:我也尝试将 onmouseover 属性直接内联为
<p style="background-color:white;padding-bottom:1%;padding-left:3.5%;padding-top:1%;margin-left:0%;border:1px solid grey;border-radius:5%;box-shadow:2px 2px 2px #999;margin-right:25%; id="comment" onmouseover="mouseOver()">'
我已经尽力了
请帮忙
【问题讨论】:
-
getElementsByClassName返回一个对象数组。你不能只在整个集合上设置一个样式,你需要循环它。 -
请不要使用完全不相关的标签
-
哪个标签不相关?
标签: javascript php html onmouseover onmouseout