javascript 改变<tr> 的class

javascript 改变<tr> 的class,第1张

“我要实现 去背景颜色改变

“鼠标放过”要用“onmouseover”这个

“onmousemove”是鼠标移动的

class的效果你已经定义了吧?(那就不用说了)

“this.class='red1' ”,语法错了,所以没有效果

应该用:this.className='red1'

这个“className”的“N”一定要大写,否则也没有效果

例:

<tr onmouseover="this.className='red1'" onmouseout="this.className='恢复的Class名称'" class="red" >

<!doctype html>

<html lang="zh-cn">

<head>

<meta http-equiv="content-type" content="text/htmlcharset=utf-8" />

<title>Document</title>

<script type="text/javascript" src="jquery-1.7.2.min.js"></script>

<style type="text/css">

.className { background-color: #333}

</style>

</head>

<body>

<table width="100%" border="1" cellspacing="0" cellpadding="0">

<tr>

<th scope="col">a</th>

<th scope="col">b</th>

<th scope="col">c </th>

<th scope="col">d </th>

</tr>

<tr><td colspan="4">e</td></tr>

<tr>

<td colspan="2">f</td>

<td colspan="2">g</td>

</tr>

<tr> <td colspan="4">h</td> </tr>

<tr>

<td>j</td>

<td>k</td>

<td>l</td>

<td>m</td>

</tr>

</table>

<script type="text/javascript">

$("td[colspan='4']").each(function(){

$(this).addClass('className')

})

//所有th

$('th').each(function(){

$(this).addClass('className')

})

</script>

</body>

</html>

//css 是不是没写啊


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/bake/11655299.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-17
下一篇 2023-05-17

发表评论

登录后才能评论

评论列表(0条)

保存