通过JavaScript获取html中的行号
我已经通过 CodeRay 突出显示了 ruby 代码,现在我想知道用户单击了哪个行号。该行号应与源代码中的行号相对应。哪种方法最好?
I've highlighted the ruby code by CodeRay and now I'd like to know on which line number user clicked. This line number should correspond to line nuber in source code. Which is the best way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是我解决这个问题的方法。
我用 CodeRay 生成了带有数字的 html。但是CodeRay在官方网站上没有准确的文档,所以在浏览了CodeRay的代码之后我做了这样的:
模式
:line_numbers =>; :table
在我的情况下无法正常工作,我应该使用:inline
模式。如果您不喜欢 html 页面中的数字,我认为您可以通过 css 或 javascript 删除它。然后我写了一个小的 javascript 函数:
任何建议和改进将不胜感激。
Here's how I resolved this question.
I generated html with the numbers by CodeRay. But CodeRay doesn't have accurate documantation on official site, so after looking throught the CodeRay's code I've made it like this:
The mode
:line_numbers => :table
doesn't work properly in my case that's I should've use:inline
mode. If you don't like numbers in your html page i think you can remove it by css or javascript.Then I wrote small javascript function:
Any suggestions and improvements will be appreciated.