[英]Staying on same page after clicking submit button
我在提交按鈕上應用了 function “myfunction”。 function在提交頁面時會顯示一個對話框,詢問用戶是否確定提交頁面?
HTML按鈕代碼為:
<h:commandButton id="submit" value="Brewery 1" onclick="myfunction()" styleClass="button1">
<f:actionListener binding="#{loginweb.setNewUsernameAndCreateUser('Brewery1')}"/>
</h:commandButton>
**function myfunction(e)**
{
if(!confirm('Are you sure to proceed with this role?')) {
e.preventDefault();
}
else {
return false;
}
}
但是當我按下取消(在出現的對話框上)時,頁面仍然被提交。 我做錯了什么? 謝謝
看起來您沒有將 click 事件傳遞給myfunction
。 試試onclick="myfunction(event)"
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.