我知道有很多关于此的帖子,但我没有运气找到有用的东西。
我在页面上有多个表单,我希望能够使用每个表单中的提交按钮一一提交。这目前对我有用:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title></title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">
<!--
$(document).ready(function() {
$(".do_submit").click(function() {
var element = $(this);
var Id = element.attr("id");
var val = $("#val" + Id).val();
var anotherval = $("#anotherval" + Id).val();
alert("Id " + Id + " val " + val + " anotherval " + anotheval);
// How do I get the name of the value of whatever submit button was clicked
});
});
-->
</script>
</head>
<body>
<form action="" method="post" name="form1" />
<input type="hidden" name="val" id="val1" value="a" />
<input type="hidden" name="anotherval" id="anotherval1" value="b" />
<input type="submit" name="SavePlantInfo" class="do_submit" id="1" value="Save" />
<input type="submit" name="SavePlantInfoAndEmail" class="do_submit" id="1" value="Save And Email" />
</form>
<form action="" method="post" name="form2" />
<input type="hidden" name="val" id="val2" value="a" />
<input type="hidden" name="anotherval" id="anotherval2" value="b" />
<input type="submit" name="Save" class="do_submit" id="2" value="Save" />
<input type="submit" name="SaveAndEmail" class="do_submit" id="2" value="Save And Email" />
</form>
</body>
</html>
我想不通的是如何知道这两个提交按钮中的哪一个被点击了。我希望能够获取名称(首选)或单击的任何提交按钮的值。
蒂亚!