問題
配合onclientclick屬性呼叫confirm()判斷是否要繼續執行
解決方法
程式流程如下:
按下確定按鈕->檢查RadioButtonList的選項,若為0則某欄位不得為空白,否則顯示"該必填欄位空白,確定繼續?!"->若"是"則繼續傳回Server端執行,若"否",則停在該頁面
程式碼片段如下:
function CheckVaild()
{
var table; //取得RadioButtonList
table=document.getElementById("RadioButtonList1");
for(i=0;i<table.rows[0].cells.length;i++)
{
if(table.rows[0].cells[i].childNodes[0].checked == true)
{
selValue = table.rows[0].cells[i].childNodes[0].value;
break;
}
//RadioButtonList=0,且必填欄位空白,跳出確認視窗
if (selValue=="0")
{
if (document.getElementById("TxtBox1").value=="")
{
var r=confirm("該必填欄位空白,確定繼續?!");
if (r==true)
{}
else
{
var mytext = document.getElementById("TxtBox1");
mytext.focus();
window.event.returnValue=false;
}
}
}
}
}
<asp:button id="btnSave" runat="server" Text="確定" OnClientClick="return CheckVaild();"></asp:button>
沒有留言:
張貼留言