2017-10-21 119 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方式