我有一个带有多个提交按钮的简单表单。如何更改java脚本以查看单击的按钮。感谢
<form class="contact" role="form" data-toggle="validator" id="testform">
<div class="form-group">
<label for="inputName" class="control-label">Name</label>
<input type="text" class="form-control" id="inputName" name="inputName" placeholder="Cina Saffary" required>
<div class="help-block with-errors"></div>
</div>
<div class="form-group">
<button class="btn btn-success" type="submit" id="save1" value="save1">save1</button>
<button class="btn btn-success" type="submit" id="save2" value="save2">save2</button>
</div>
</form>
$('#testform').validator().on('submit', function (e) { (e.isDefaultPrevented()) {
alert("failure!");
} else {
// if save1 clicked, alert("save1 was clicked");
// if save2 clicked, alert("save2 was clicked");
}
});
答案 0 :(得分:0)
你可以得到这样的按钮值:
RelativeLayout r1 = (RelativeLayout) findViewById(R.id.relativelayout1);
r1.setBackgroundResource(R.drawable.sample);
您还需要为按钮再添加一个事件
var val = $("button[type=submit][clicked=true]").val();
参考:How can I get the button that caused the submit from the form submit event?