只有按钮onclick有效,<a onclick=""> tag doesn&#39;t work in javascript when sending parameter to another page

时间:2016-09-09 19:25:58

标签: javascript html onclick

First <a tag> onclick --> doesn't work (a tag onclick) but second button onclick --> works.

Anyone knows what's the problem with <a> tag??

function content(frm) {
  var url = "noticeContent.jsp";
  var title = "test";
  var status = "toolbar=no,directories=no,scrollbars=no,resizable=no,status=no,menubar=no,width=240, height=200, top=0,left=20"
  window.open("", title,status);
  frm.target = title;
  frm.action = url;
  frm.method = "post";
  frm.submit();
}

<form name="f_name">
  <input type="hidden" name="a" value="1">
    <input type="hidden" name="b" value="2">
      <td><a href="javascript:" onclick="content(this.form)"></a></td>
      <td><input type="button" onclick="javascript:content(this.form)"></td>
</form>

1 个答案:

答案 0 :(得分:0)

将返回false添加到<a>代码,以避免<a>的默认行为

<td><a href="javascript:" onclick="content(this.form);return false;"></a></td>

但是我会建议你将javascript和HTML分开以便于阅读,而不是在这种情况下使用锚标记。