当我从按钮提交时,帖子有一个参数"提交"=>"保存更改"自动与按钮的文本相关联
当我在脚本内提交时
document.choices.submit()
我没有得到这个参数,只有表单数据。 我需要确定提交源,因此需要从脚本中指定一个"提交"值
如何添加"提交"参数。
由于表单事件是在按钮单击之后,事件来源将是表单,因此恕我直言,最好在提交点击事件之前检测点击:
const myForm = document.getElementById('myForm');
// Button #1
document.getElementById('submit1').onclick = () => {
console.log('submit1');
myForm.submit();
};
// Button #1
document.getElementById('submit2').onclick = () => {
console.log('submit2');
myForm.submit();
};
<Form id="myForm">
<input type="text" />
<button id="submit1">Submit #1</button>
<button id="submit2">Submit #2</button>
</Form>
也许使用<button>
而不是<input type="submit" />
或为提交按钮添加方法preventDefault()
来跟踪您的问题并自定义按钮行为。
好的 -所以当我考虑它时非常简单 - 我只是在提交之前附加了一个输入,其中包含我想要的详细信息
$dialogContainer.dialog({ 显示:"显示", 模态:对, dialogClass: 'archive-dialog', 按钮:[ { 文本:"取消", 班级:"BTN-中学", 单击: 函数 () { $(this).dialog('close') $(this).dialog('destroy').remove() } }, { 文本:"确认", 类:"BTN-小学", 编号: 'btn_confirm', 单击: 函数 () { $(this).dialog('close') $(this).dialog('destroy').remove() $('form[name=choices]').append(")document.choices.submit()} }] }).prev().find('.ui-dialog-titlebar-close').hide()//隐藏标准关闭按钮
将输入附加到提交表单只是给了我从按钮提交会给出的参数。 但有新文本