2017-10-21 81 views
1

这里我想用css设置我的表格样式。但是,当我尝试添加内部回声这个事件,它说,PHP/CSS onmouseover和onmouse不支持PHP echo

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

由于我是一个初学者到PHP,我想不出确切的错误。任何有用的建议来编辑我的代码?谢谢!

我的代码:

echo "<tr onmouseover = /"this.style.backgroundColor = /'#ffff66' ; " onmouseout = /"this.style.backgroundColor = /'#d4e3e5';">"; 

回答

1

这工作太:

echo "<tr onmouseover='this.style.backgroundColor=#ffff66' onmouseout='this.style.backgroundColor=#d4e3e5'>"; 
+0

谢谢@Daniele_Fois这工作! :) –

1

更改它来调用JavaScript函数: 在changeColor功能

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

+0

谢谢您的建议@Iasha但我想添加内联:) –

2

点之一,onmouseoveronmouseout是JavaScript事件。
第二点,你可以使用css中的:hover
观点三,你只需要呼应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> 
 
<div id="css"> 
 
</div>

我添加了一个片段同时显示cssJavaScript方式