一个jsf(facelets)与javaScript问题

来源:百度知道 编辑:UC知道 时间:2024/07/04 09:41:18
我在.xhtml文件添加如下javaScript代码
<script language="javascript">
var rows = document.getElementsByTagName('tr');
for(var i=0;i<rows.length;i++){
rows[i].onmouseover = function(){ //鼠标在行上面的时候
this.className += 'altrow';
}
rows[i].onmouseout = function(){ //鼠标离开时
this.className = this.className.replace('altrow','');
}
}

却出现 Element type "rows.length" must be followed by either attribute specifications, ">" or "/>".
谁知道我哪儿错了啊????

因为是在xml文档里,所以script的子元素并未被指定是cdata类型
在script前后加上
<script type="application/javascript"><![CDATA[
//...
]]></script>

XHTML语言比html语言严格多了。所有标签必须有结束标签。单表签必须以/>结尾。
编译器把你的小于号当作标签解析了。
另外xhtml不直接兼容js的。