繁体   English   中英

javascript中未调用javascript函数

[英]javascript function not being called in php

所以我有这段代码:

<?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!!! &nbsp;&nbsp;&nbsp;&nbsp;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();

发生的事情是,它为一行称为“注释”的所有项目进行选择,然后美化每个注释(每行注释中的项目),并且每个注释上都出现了一个图像(“喜欢”和“不喜欢”图标),除了我在鼠标悬停在id =“ comment”的注释段落上之前,不希望显示图像。但是发生的是,我立即加载页面,注释已经突出显示,这是我想在鼠标悬停时发生的事情在该段的意见“,当我尝试过意见,悬停和“unhover(如果有这样:-)一个字)”,它不变成蓝色,但根据我的代码,它应该变成蓝色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

而且不知道那意味着什么...

注意:我也尝试将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()">'

我已经尽力了

请帮忙

这是因为jQuery对象没有样式属性。

尝试这个:

d.css.("backgroundColor", "red");

如果您想使用DOM API,则可以进行传统的DOM选择:

document.getElementById("surmenu").style.backgroundColor="red";

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM