Html表单+主播回发麻烦

时间:2011-01-27 23:48:31

标签: javascript html

有以下样本:

<form id="form" name="form" method="post">
    <a id="submit1" name="submit1" href="javascript:doPostBack('submit1', '')">#1</a>
    <a id="submit2" name="submit2" href="javascript:doPostBack('submit2', '')">#2</a>
    <a id="submit3" name="submit3" href="javascript:doPostBack('submit3', '')">#3</a>
</form>

doPostBack函数代码应该是什么,以便在服务器上我可以区分哪个锚被按下了?

1 个答案:

答案 0 :(得分:0)

您可以使用隐藏的输入元素来跟踪提交源,并在服务器端检查提交源。 e.g:

<form id="form" name="form" method="post">
    <input type="hidden" value="" name="submitSource"/>
    <a id="submit1" name="submit1" onclick="registerSubmitSource(this)" href="javascript:doPostBack('submit1', '')">#1</a>
    <a id="submit2" name="submit2" href="javascript:doPostBack('submit2', '')">#2</a>
    <a id="submit3" name="submit3" href="javascript:doPostBack('submit3', '')">#3</a>
</form>
<script type="text/javascript">
 function registerSubmitSource(el)
 {
  var submitSource = document.getElementById("submitSource");
  submitSource = el.tagName; 
  return;
 }
</script>