DropDownList 選項改變確認腳本

需要這個, 到網找了某先生的腳本改了改

static public string DropDownListSelectChangeConfirmScript(string dropDownListId,string message)
{
    
string script = " <script> \n"
        
+" var fooIndex; \n"
        
+" function saveIndexes() \n"
        
+" { \n"
        
+"    fooIndex = document.all['"+dropDownListId+"'].selectedIndex; \n"
        
+" } \n"
        
+" function resetIndexes() \n"
        
+" { \n"
        
+"    document.all['"+dropDownListId+"'].selectedIndex = fooIndex; \n"
        
+" } \n"
        
+" function areYouSure() \n"
        
+" { \n"
        
+"    if( !confirm('"+message+"')) \n"
        
+"    { \n"
        
+"      resetIndexes(); \n"
        
+"      return false; \n"
        
+"    } \n"
        
+"    else \n"
        
+"    { \n"
        
+"      document.all['"+dropDownListId+"'].detachEvent('onchange', areYouSure); \n"
        
+"      return true; \n"
        
+"    } \n"
        
+" } \n"
        
+" saveIndexes(); \n"
        
+" document.all['"+dropDownListId+"'].attachEvent('onchange', areYouSure); "
        
+"</script>\n";
    
return script;
}

private void RegisterClientScript(string dropDownListClientId)
{
    
string script = DropDownListSelectChangeConfirmScript(
        dropDownListClientId,
        
"Are you sure?"
        );
    
if(!IsStartupScriptRegistered("startup"))
    
{
        RegisterStartupScript(
"startup",script);
    }


}

posted on 2005-12-07 15:37  z_true  阅读(338)  评论(0编辑  收藏  举报

导航