我喜欢这个
<form id="popisgolubova_form">
<input name="pregledaj" type="button" formaction="uredigoluba.php" formmethod="post" formtarget="_self" value="pregledaj" class="button" onclick="popisgolubova_radiobutton(this)">
<input name="rodovnik" type="button" formaction="rodovnik.php" formmethod="post" formtarget="_blank" value="rodovnik" class="button" onclick="popisgolubova_radiobutton()">
<input name="podaci" type="button" value="poodaci" formaction="podaciogolubu.php" formmethod="post" formtarget="_blank" class="button" onclick="popisgolubova_radiobutton()">
</form>
和javascript
function popisgolubova_radiobutton(element)
{
alert($(element).find("[formaction]").val());
var popisgolubova_radiobutton=$("input[name=RadioGroup1]").is(":checked");
if(popisgolubova_radiobutton==false)
{
alert("nop");
}
else
{
$("form#popisgolubova_form").submit();
}
}
首先,我正在检查是否检查了任何复选框,如果是,我可以提交表格。但问题是形成,形式方法和形式目标。如何获取并提交它们
要获取表单的操作或方法属性,您可以尝试以下操作:
$(function() {
var action = $("#formid").attr('action'),
method = $("#formid").attr('method');
});
希望这有助于找到解决问题的想法
<form id="popisgolubova_form">
<input name="pregledaj" type="button" formaction="uredigoluba.php" formmethod="post" formtarget="_self" value="pregledaj" class="button postForm"/>
</form>
$(document).on('click', '.postForm', function () {
$('#popisgolubova_form').attr('action', $(this).attr('formaction'));
$('#popisgolubova_form').attr('method', $(this).attr('formmethod'));
$('#popisgolubova_form').attr('formtarget', $(this).attr('formtarget'));
});
所以问题是谈论不幸的名字
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#attr-formaction
...这是一种覆盖的方式
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form#attr-action
每次单击正确设置提交按钮。您要检查的地方是在提交时 - 当您确定实际提交的内容时。
您用于提交的按钮存储为:focus - 此时似乎没有以其他方式存储在事件对象中。
$('form').on("submit", function(event) {
if( $(':focus').is('[formaction]') ) {
console.warn($(':focus').attr('formaction'));
}
if( $(':focus').is('[formtarget]') ) {
console.warn($(':focus').attr('formtarget'));
}
});
if( $(':focus').is('[formaction]') ) {
console.log($(':focus').attr('formaction'));
}