使用javascript重置HTML表格上的行样式 [英] Resetting row style on an HTML table using javascript
问题描述
大家好
我正在用MVC 4编写应用程序,我正在动态构建一个表。单击该表以在表格下方的窗口中显示与选择相关的内容。
要向用户显示他们选择的内容,我将在所选行上设置CSS类,以便对其进行不同的样式设置。这很好用,但我不知道如何重置表中的所有其他行,以便只有一个不同颜色的行。
任何人都可以帮助?
我以为我可以使用javascript来遍历行,但我无法弄清楚如何使用它来设置CSS类?
谢谢
没关系。一个筋疲力尽的大脑和饥饿的情况。
经过一些咖喱,以及一些红莓苹果酒,我意识到我是傻瓜......
如果其他人对此有逻辑阻止,这就是我所做的。
我只是有一个变量包含我点击的项目,以便稍后查看。在例行程序中设置此项。然后下次我解雇例行程序时,用它将原来的程序改回原来的程序。
var prevItem;
('。update-list-item')。click(function(e){
if(prevItem!= null)
(prevItem ).removeClass('update-list-item2')。addClass('update-list-item');
prevItem = this;
Hi guys
I'm writing an app with MVC 4, and I'm dynamically building a table. The table is to be clicked to display things related to the selection in a window below the table.
To show the user which they have selected, I am setting the CSS class on the selected row so that it is styled differently. This works great, BUT I don't know how to reset all the other rows in the table so that there is only the one differently colored row.
Can anyone help?
I thought I could use javascript to iterate through the rows, but I can't figure out how to use this to set the CSS class?
Thanks
Doesn't matter. A case of exhausted brain and hunger.
After some curry, and a few swigs of Red Berry Cider, I realised I was being dumb...
In case anyone else gets logic block on this, here is what I did.
I simply had a variable to contain the item I clicked on so that I can look at it later. Set this during the routine. Then next time I fire the routine, use it to change the old one back to what it should be.
var prevItem;
('.update-list-item').click(function (e) { if(prevItem != null)
(prevItem).removeClass('update-list-item2').addClass('update-list-item'); prevItem = this;
这篇关于使用javascript重置HTML表格上的行样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!