Having the following sample:
<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="sub开发者_StackOverflow社区mit3" name="submit3" href="javascript:doPostBack('submit3', '')">#3</a>
</form>
What is the doPostBack function code should be, so that on the server I could distinguish which anchor was pressed?
You can use a hidden input element to track the source of submit and at the server end check the source of submit. 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>
精彩评论