addClass 使用 .live() 和 jQuery
我目前正在使用 .load()
函数将内容动态加载到容器 div
中。正在加载的内容是我想要斑马条纹的表格数据。斑马条纹在静态页面上很容易,但我不知道如何对加载到容器 div
中的新内容进行斑马条纹。
这是我正在尝试使用的代码:
$("table tbody tr:even").live("EVENT", function(){
$(this).addClass("alt");
});
“EVENT”不应该是“click”
或“mouseover”
,而是“onload”或类似的东西。有办法做到这一点吗?感谢您的建议!
〜贾里德
I am currently using the .load()
function to load content into a container div
dynamically. The content being loaded is table data which I'd like to zebra stripe. The zebra striping is easy on a static page, but I can't figure out how to zebra stripe the new content loaded into the container div
.
Here's the code with which I'm trying to work:
$("table tbody tr:even").live("EVENT", function(){
$(this).addClass("alt");
});
The "EVENT" shouldn't be "click"
, or "mouseover"
but "onload" or something to that effect. Is there a way to do this? Thanks for your suggestions!
~Jared
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

发布评论
评论(4)
作为 tvanfosson 答案的扩展(在这种情况下这是你最好的选择), live() 函数目前仅支持某些事件。这是来自 http://api.jquery.com/ 的文档:
可能的事件值:click、dblclick、mousedown、mouseup、mousemove、mouseover、mouseout、keydown、keypress、keyup
目前不支持:blur、focus、mouseenter、mouseleave、change、submit
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
您应该只在 load() 的回调函数中运行斑马条纹代码。
You should just run the zebra striping code in the callback function for the load().