尝试优化 SharePoint 页面中使用的 jQuery 函数
我正在尝试优化下面的 jQuery 代码,它会迭代页面上的所有 TD 标签,搜索任何具有“eventClassXXXXXX”作为其类属性的标签(其中“XXXX”可以是数字或字母)。
$(document).ready(function () {
$("td").each(function () {
$(this).attr("class", this.className.replace(/eventClass/gi, 'eventClass '));
});
});
所以它会变成
"<TD class='eventClass12345678'>"
问题
"<TD class='eventClass'>
是它需要很长时间才能在共享点页面上运行(右键单击共享点页面并单击查看源代码以了解原因)。我必须这样做的原因是因为我正在尝试重新设计页面上的第三方 Web 部件(未作为开源提供)
如果您对优化此或其他方式有任何想法,请告诉我。谢谢
谢谢
I'm attempting to optimise the jQuery code below, it iterates through all the TD tags on the page searching for any that has "eventClassXXXXXX" as its class attribute (where "XXXX" could be numeric or alphabetic).
$(document).ready(function () {
$("td").each(function () {
$(this).attr("class", this.className.replace(/eventClass/gi, 'eventClass '));
});
});
so it would change
"<TD class='eventClass12345678'>"
to
"<TD class='eventClass'>
The problem is it takes ages to run on a sharepoint page (right-click on a sharepoint page and click view source to see why). The reason I have to do this is becauyse there is a third party webpart on the page that I'm attempting to restyle (wasn't supplied as open-source)
Let me know if you have any ideas on optimizing this or another way round. Thanks
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许这样的东西会更快:
如果有某种可用的容器元素(也许是表格),这会更好:
Maybe something like this would be faster:
If there's some sort of container element available (perhaps the table), this would be much better: