我试图将backAfterSaveStatus值绑定到隐藏输入,由于某种原因,提交的表单backAfterSave值为空。之后我返回并再次提交表单 -backAfterSave值为 1。问题出在哪里?我尝试了同样的事情prevent,submit()但它仍然不起作用。x-text另外,我在表单提交之前转储了 div,并且代码使隐藏输入 1 。我做错了什么?
<form action="<...>" method="post">
<div x-data="{
backAfterSaveStatus: '',
backAfterSave () {
this.backAfterSaveStatus = '1';
document.querySelector('form.withBackAfterSave').submit();
}
}">
<input name="backAfterSave" :value="backAfterSaveStatus">
<div>
<span>
<button x-on:click.prevent="backAfterSave()" type="submit">
Save & back
</button>
</span>
<span>
<button type="submit">
Save
</button>
</span>
</div>
</div>
</form>
我想要与下面相同的结果:
let buttonBackAfterSave = document.getElementById('button-back-after-save');
if (buttonBackAfterSave) {
buttonBackAfterSave.addEventListener('click', () => document.getElementById('input-back-after-save').value = 1);
}
汪汪一只猫
牛魔王的故事
跃然一笑
相关分类