本文介绍了单击确定,然后隐藏值应为1,但它显示为0。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Public void GetData(){                
HtmlInputHidden hdnfld = new HtmlInputHidden();
                StringBuilder sb = new StringBuilder();
                sb.Append(@"<script type='text/javascript'>");
                sb.Append(@"var r = confirm('do you want to Checked-Out?');");
                sb.Append(@"if(r == true)");
                sb.Append(@"{");               
                hdnfld.value="1";
                sb.Append(hdnfld);
                sb.Append(@"}");
                //For cancel
                sb.Append(@"else");
                sb.Append(@"{");
                sb.Append(@"alert('before failure');");
                hdnfld.value="0";
                sb.Append(hdnfld);
                sb.Append(@"}");
                sb.Append(@"</script>");
}





我的尝试:





What I have tried:

Public void GetData(){                
HtmlInputHidden hdnfld = new HtmlInputHidden();
                StringBuilder sb = new StringBuilder();
                sb.Append(@"<script type='text/javascript'>");
                sb.Append(@"var r = confirm('do you want to Checked-Out?');");
                sb.Append(@"if(r == true)");
                sb.Append(@"{");               
                hdnfld.value="1";
                sb.Append(hdnfld);
                sb.Append(@"}");
                //For cancel
                sb.Append(@"else");
                sb.Append(@"{");
                sb.Append(@"alert('before failure');");
                hdnfld.value="0";
                sb.Append(hdnfld);
                sb.Append(@"}");
                sb.Append(@"</script>");
}

推荐答案


HtmlInputHidden hdnfld = new HtmlInputHidden();
           StringBuilder sb = new StringBuilder();
           sb.Append(@"<script type='text/javascript'>");
           sb.Append(@"var r = confirm('do you want to Checked-Out?');");
           sb.Append(@"if(r == true)");
           sb.Append(@"{");
           sb.Append(@"document.getElementById('hdnfld').value='1'"); 
           sb.Append(@"}");
           //For cancel
           sb.Append(@"else");
           sb.Append(@"{");
           sb.Append(@"alert('before failure');");
           sb.Append(@"document.getElementById('hdnfld').value='0'"); 
           sb.Append(@"}");
           sb.Append(@"</script>");



这篇关于单击确定,然后隐藏值应为1,但它显示为0。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 13:03