attr 在 Chrome 和 safari 中不起作用

发布于 2024-12-05 01:59:15 字数 166 浏览 0 评论 0原文

我已使用以下调用函数将 onclick 插入到所有内容中: onclick="javascript:loadcontent($(this).attr('rel'));

此代码在 Firefox 和 IE 中正常工作,但在 Chrome 中无效

我该如何修复它?

I've insert onclick to all with below call function :
onclick="javascript:loadcontent($(this).attr('rel'));

this code working corectly in Firefox and IE but not in Chrome

How can I fix it ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

久隐师 2024-12-12 01:59:15
<a href="" id="someSpecificLink">Try this instead</a>

$('#someSpecificLink').live('click', function(e) {
  e.preventDefault();
  loadcontent($(this).attr('rel'));
});
<a href="" id="someSpecificLink">Try this instead</a>

$('#someSpecificLink').live('click', function(e) {
  e.preventDefault();
  loadcontent($(this).attr('rel'));
});
花开半夏魅人心 2024-12-12 01:59:15
  • 删除 javascript:。这是没有必要的。
  • 跳过 jQuery 的 attr() 方法。这里没有任何好处。

onclick="loadcontent(this.rel)";

也就是说,这些都是优化。没有明显的原因说明该代码在大多数浏览器中不起作用。检查浏览器的控制台是否有错误。

  • Remove the javascript:. It's unnecessary.
  • Skip jQuery's attr() method. There's no benefit to it here.

onclick="loadcontent(this.rel)";

That said, these are both optimizations. There's no obvious reason why that code wouldn't work in most browsers. Check the browser's console for errors.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文