Javascript 如何为a<;使用默认值;a>;一排

Javascript 如何为a<;使用默认值;a>;一排,javascript,html,Javascript,Html,我有一个如下所示的html表: <table id="tabRoom" style="border: currentColor; border-image: none; width: 950px;"> <thead> <tr> <th class="ui-widget-header">ID</th> <th class="ui-widget-header">Name</th>

我有一个如下所示的html表:

<table id="tabRoom" style="border: currentColor; border-image: none; width: 950px;">
  <thead>
    <tr>
      <th class="ui-widget-header">ID</th>
      <th class="ui-widget-header">Name</th>
    </tr>
  </thead>
  <tbody>
    <tr class="gridrow" onclick="editRoom(650);">
      <td class="ui-widget-content myclass" style="width: 10%;"> 
        <a style="display: inline;" href="/Config/Rooms/303">ID01</a>
      </td>
      <td>
        John Brown>
      </td>
    </tr>
  </tbody>
</table>

如果要使用jQuery:

$(window).load(function() {
    $('table a').click(function(event) {
        event.preventDefault();

        //display popup
    });
});

为了使它干净,为什么不将重定向代码放在onclick事件函数中

JS:
功能编辑室(id){
//做点什么
window.href.locaiton='/myurl';

}

答案的代码类型

var elements=document.getElementsByClassName(“弹出”);
对于(var i=0;i


你有JS代码吗?$('a')。点击(函数(e){e.preventDefault();});如果链接没有任何用途,为什么不删除它呢?谢谢你的回答,但我需要添加一个js代码来防止用户访问href链接。我不应该改变editRoom(650)place$(window).load(function(){})=>$(function(){})这对我来说并没有阻止作用?所以@xAqweRx,你可以用至少5种不同的方式编写它,它是有效的,没有理由对一个有效的解决方案投否决票。Emes Uras您一定是做错了什么,因为这肯定会阻止您点击表中的链接。@MarioPlantosar我没有投票否决您。这只是假设。或者有人心情不好
$(window).load(function() {
    $('table a').click(function(event) {
        event.preventDefault();

        //display popup
    });
});