2017-10-21 11:58

PHP / CSS onmouseover和onmouse out不适用于PHP echo


Here I want to style my table with css. But when I try to add this events inside echo, it says,

Parse error: syntax error, unexpected 'this' (T_STRING), expecting ',' or ';' in E:\xampp\htdocs\Ceylon Aviation\Flights.php on line 146

As I'm a beginner to PHP, I can't figure out the exact error. Any helpful suggestions to edit my code? Thank You!

My Code:

echo "<tr onmouseover = /"this.style.backgroundColor = /'#ffff66' ; " onmouseout = /"this.style.backgroundColor = /'#d4e3e5';">";
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答


  • drzablspw01655860 drzablspw01655860 4年前

    This works too:

        echo "<tr onmouseover='this.style.backgroundColor=#ffff66' onmouseout='this.style.backgroundColor=#d4e3e5'>";
    点赞 评论 复制链接分享
  • douyun1972 douyun1972 4年前

    Point one, onmouseover and onmouseout are JavaScript events.
    Point two, you can use the :hover from css.
    Point three, you only need to echo the html

    var div = document.getElementById("js");
    //set width and height
       div.style.width = "100px";
       div.style.height = "100px";
    //set the start color
       div.style.backgroundColor = "#F0F";
    function OnMouseOver(o) {
       o.style.backgroundColor = "#F00";
    function OnMouseOut(o) {
       o.style.backgroundColor = "#F0F";
    #css {
      width: 100px;
      height: 100px;
      background-color: #0FF;
    #css:hover {
      background-color: #00F;
    <div id="js" onmouseover="OnMouseOver(this)" onmouseout="OnMouseOut(this)">
    <div id="css">

    I added a snippet to show both css and JavaScript ways

    点赞 评论 复制链接分享
  • drexlz0623 drexlz0623 4年前

    Change it to call javascript functions: in changeColor function

    function changeColor(){ this.style.backgroundColor = '#ffff66'; }

    点赞 评论 复制链接分享