jQuery 不替换 ReportViewer 中的文本
我正在尝试使用 jQuery 替换在 ReportViewer 中返回的文本。我的 div 包裹在表格单元格中,将“空”显示为文本 - 我计划在客户端将其替换为我自己的格式化文本。
我可以使用 jQuery 很好地在 div (位于 td 元素内)上设置一个类。示例:
jQuery('div:contains("empty")').addClass('replacetext');
但由于某种原因我无法执行此操作:
jQuery('div:contains("empty")').replaceWith('<div>Hello World</div>');
我在页面上的其他一些元素上尝试了此操作,并且 jQuery 确实有效...但此问题似乎是 ReportViewer(我使用的是 2008)特定的。
I'm trying to replace text that I got back in the ReportViewer using jQuery. My div, wrapped in the table cell, display "empty" as text - which I plan on replacing with my own formatted text on the client side.
I can use jQuery just fine to set a class on the div (which is inside a td element). Example:
jQuery('div:contains("empty")').addClass('replacetext');
But for some reason I cannot do this:
jQuery('div:contains("empty")').replaceWith('<div>Hello World</div>');
I tried this out on some other elements on the page and jQuery does work... but it seems like this issue is ReportViewer (I'm using 2008) specific.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我遇到的关键问题和问题有点不同。
我设置类的方式 - 选择器是通用的,表嵌套有大量的 div、表和行。其中许多是不必要的,但归咎于 ReportViewer。
所以解决方案是特异性,这就是我用来在非常细粒度的级别上选择级别的方法:
我使用了一种样式来标记有罪的人,因为我讨厌使用 IE6 和开发工具栏与 firebug 不符。
很难查明错误,因为我在脚本顶部有另一个 jQuery,但我没有注意到它弄乱了逻辑。
The key problem I encountered was a bit different from the question.
The way I was setting the class - the selector was general and the table was nested with a soup of divs and tables and rows. Many of which are uncessary but blame that on the ReportViewer.
So the solution is specificity which is what I used to select the level at a very granular level:
And I used a style, to mark the guilty since I have the horror of working with IE6 and the dev toolbar is not up to par with firebug.
It was hard to pinpoint the error since I was had another jQuery at the top of the script which I didn't notice that was messing up the logic.