日期:2014-05-17  浏览次数:20724 次

DTD XHTML 1.0 Strict标准中css使用Event (event:expression)属性不起作用,怎么办?
下面的代码,不添加DTD XHTML 1.0 Strict限制, css中event javascript就可以运行,加上就无法运行..怎么办?

HTML code

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns:o="urn:schemas-microsoft-com:office:office" __expr-val-dir="ltr" lang="zh-cn" dir="ltr">
   
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>rowIndex</title>
    <style media="all" type="text/css">
    <!-- 
    body
    {
    margin: 0px;
    font-family: 宋体, MS Song;
    font-size: 9pt;
    color: windowtext;
    background: threedface;
    }
    div.Page_Load
    {
    margin-left: 40px;
    margin-top: 20px;
    }
    table.Main
    {
    border: 1px solid #A9A9A9;
    width: 400px;
    background-color: White;
    }table.Main tr
    {
    background-color: expression( (this.rowIndex%2==0) ? "#F7F7F7" : "#FFFFFF" );
    event:expression(
     onmouseover = function()
     {
     this.style.backgroundColor = ( this.style.backgroundColor != '#efefef' ? '#efefef' : ( (this.rowIndex % 2 == 0) ? "#F7F7F7" : "#FFFFFF") )
     },
     onmouseout = function()
     {
     this.style.backgroundColor = ( this.style.backgroundColor != '#efefef' ? '#efefef' : ( (this.rowIndex % 2 == 0) ? "#F7F7F7" : "#FFFFFF") )
     }
    )}table.Main tr td
    {
    text-indent: 1.2em;
    }-->
    </style>
    </head><body>
    <div class="Page_Load"><table class="Main">
    <tr>
    <td>1</td>
    </tr>
    <tr>
    <td>2</td>
    </tr>
    <tr>
    <td>3</td>
    </tr>
    <tr>
    <td>4</td>
    </tr>
    <tr>
    <td>5</td>
    </tr>
    <tr>
    <td>6</td>
    </tr>
    <tr>
    <td>7</td>
    </tr>
    <tr>
    <td>8</td>
    </tr>
    <tr>
    <td>9</td>
    </tr>
    </table></div>
    </body>
    </html>
    






------解决方案--------------------
可能是 css中event javascript 不符合DTD XHTML 1.0 Strict的标准,所以无效
------解决方案--------------------
DTD XHTML 1.0 Transitional 试试
------解决方案--------------------
或者不要用 css event javascript ,而采用js的方法
------解决方案--------------------
expression语法以后都废除了,采用js才是根本的解决方法
------解决方案--------------------

lz肯定用的是 IE8 吧。由于IE中对于某些CSS特性的支持不足,为了弥补浏览器对一些CSS特性的支持的不足。从IE5开始引入CSS Expression,并且在IE8标准模式中被废弃(参见:Ending Expressions)
它是IE特有的,但IE8的标准模式和其他浏览器不支持。
想要实现类似的功能,只能依靠JS和DOM了