本文介绍了行和列......的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 亲爱的, 我有这个, < table> < colgroup> < col id =" column1" /> < col id =" column2" /> < col id =" column3" /> < / colgroup> < tr onmouseover =" do hi-light" onmouseout =" undo hi-light"> < td>< / td> < td>< / td> < td>< / td> < / tr> < / table> 我可以在前两列上进行高亮照明,除了最后一次鼠标 移动行,但现在我想不要在最后一次点亮行 列已经结束了,因为我在最后一列上有三个单独的链接 cell。当一行被选中时,是否可以知道选择了哪一列?我不想在其中设置任何属性< td> 我可以在onmouseover / out函数中检查它吗? 问候, Wandy 解决方案 Wandy Tang写道: 我不确定我有没有理解你想要的东西,但这里有一个例子 检查< td>的cellIndex属性元素: <!DOCTYPE HTML PUBLIC" - // W3C // DTD HTML 4.01 // EN" " http:// www .w3.org / TR / html4 / strict.dtd"> < html lang =" en"> < head> < title> cellIndex< / title> < script type =" text / javascript"> 功能高亮显示(row,evt,backgroundColor ){ var sourceElement; if(evt.srcElement){ sourceElement = evt.srcElement; } else if(evt.target){ sourceElement = evt.target; if(sourceElement.nodeType!= 1){ sourceElement = sourceElement.parentNode; } } if(sourceElement == row&& row .style){ row.style.backgroundColor = backgroundColor; } else { var targetCell = sourceElement; while(targetCell&& targetCell.tagName.toLowerCase()!=''td''){ targetCell = targetCell.parentNode; } if(targetCell&& targetCell.cellIndex!= 2){ row.style.backgroundColor = backgroundColor; } } } < / script> < / head> < body> < table border =" 1"> < tbody> < tr onmouseover =" highlight(this,event,''lightblue'');" onmouseout =" highlight(this,event,'''')"> < td> 0,0 < / td> < td> 0,1 < / td> < td> 0,2 < a href =" http://JavaScript.FAQTS.com/"> ; JavaScript.FAQTs.com< / a> < / td> < / tr> < / tbody> < / table> < / body> < / html> 这样整行(< tr>)改变了backgroundColor,但只有当你将鼠标移到第一个或第二个单元格上时才会改变它。 - Martin Honnen http://javaScript.FAQTs.com/ 很好 这样整行(< tr>)改变了backgroundColor,但只有当你将鼠标移到第一个或第二个单元格上时才会改变它。 改变了两种情况的发生 row.style.backgr oundColor = backgroundColor; 到 row.firstChild.style.backgroundColor = backgroundColor; row.firstChild .nextSibling.style.backgroundColor = backgroundColor; - Evertjan。 荷兰。 (请将x''es更改为我的电子邮件地址中的点数, 但请让我们继续讨论新闻组) Dear All,I have this,<table><colgroup><col id="column1" /><col id="column2" /><col id="column3" /></colgroup><tr onmouseover="do hi-light" onmouseout="undo hi-light"><td></td><td></td><td></td></tr></table>I can do the hi-light on the first two columns except the last when mousemoveover the row, but now I want to not hi-lighting the row when the lastcolumn is being over, coz I have three separate links on the last columncell. Is it possible knowing which column is being selected when a row isselected? I do not want to set any attribute inside <td>Can I check it inside the onmouseover/out function?Regards,Wandy 解决方案The fact that the onmouseover and onmouseout fire at all is odd.Function names can not contain spaces, and it should include the () partof the function call. Let me guess, you are testing in IE?--Randycomp.lang.javascript FAQ - http://jibbering.com/faqI am not sure I have understood what you want but here is an examplechecking the cellIndex property of a <td> element:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd"><html lang="en"><head><title>cellIndex</title><script type="text/javascript">function highlight (row, evt, backgroundColor) {var sourceElement;if (evt.srcElement) {sourceElement = evt.srcElement;}else if (evt.target) {sourceElement = evt.target;if (sourceElement.nodeType != 1) {sourceElement = sourceElement.parentNode;}}if (sourceElement == row && row.style) {row.style.backgroundColor = backgroundColor;}else {var targetCell = sourceElement;while (targetCell && targetCell.tagName.toLowerCase() != ''td'') {targetCell = targetCell.parentNode;}if (targetCell && targetCell.cellIndex != 2) {row.style.backgroundColor = backgroundColor;}}}</script></head><body><table border="1"><tbody><tr onmouseover="highlight(this, event, ''lightblue'');"onmouseout="highlight(this, event, '''')"><td>0, 0</td><td>0, 1</td><td>0, 2<a href="http://JavaScript.FAQTS.com/">JavaScript.FAQTs.com</a></td></tr></tbody></table></body></html>That way the whole row (<tr>) changes the backgroundColor but only ifyou move the mouse over the first or second cell.--Martin Honnen http://JavaScript.FAQTs.com/Nice That way the whole row (<tr>) changes the backgroundColor but only if you move the mouse over the first or second cell.change both occurances ofrow.style.backgroundColor = backgroundColor;torow.firstChild.style.backgroundColor = backgroundColor;row.firstChild.nextSibling.style.backgroundColor = backgroundColor;--Evertjan.The Netherlands.(Please change the x''es to dots in my emailaddress,but let us keep the discussions in the newsgroup) 这篇关于行和列......的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-05 21:46