当前位置: 代码迷 >> ASP.NET >> 怎么获取html控件的值?
  详细解决方案

怎么获取html控件的值?

热度:8290   发布时间:2013-02-25 00:00:00.0
如何获取html控件的值????
C# code
我前台基本上判断好了,,前台代码 <script language="javascript" type="text/javascript">        var len;        var sum;        var maxnum = 100000;//最大投注金额        var issue  ='8878'                var ishave ='1'                function chCI(idval)        {                    if(issue=='3131')            {               if (document.getElementById("CI"+idval).checked == true)                {                    document.getElementById(idval).value = 1;                }                else                {                    document.getElementById(idval).value = 0;                }            }            else            {                if (document.getElementById("CI"+idval).checked == true)                {                    document.getElementById(idval).value = 10;                }                else                {                    document.getElementById(idval).value = 0;                }            }            fo(idval);        }        function fo(idval)        {            var regex=/^[1-9]\d{0,}$/;            var val;            len = document.getElementsByName("SMONEY").length;            sum = 0;            for (i=0;i<parseInt(len);i++)            {                val = document.getElementsByName("SMONEY")[i].value;                if(regex.test(val)&&(document.getElementsByName("CI")[i].disabled==false))                {                    document.getElementsByName("CI")[i].checked = true;                    sum = parseInt(sum)+parseInt(val);                                                                         }                else if (document.getElementsByName("CI")[i].disabled==false)                {                    document.getElementsByName("CI")[i].checked = false;                    document.getElementsByName("SMONEY")[i].value = "";                }            }            if (parseInt(sum)>parseInt())            {                document.getElementById(idval).value = "";                fo(idval);                alert("您的经验不足!");            }                        if(sum>maxnum)            {              alert("对不起,总投注金额不能超过投注上限!");               return false;            }                                    document.getElementById("SMONEYSUM").value = sum;        }          </script>  <asp:Repeater ID="rpt310GuessAdd" runat="server" onitemdatabound="rpt310GuessAdd_ItemDataBound"                >            <HeaderTemplate>                               <table class="sanyaolingtables sanyaolingTable" style=" border-collapse:collapse;font-weight:bold; "><tr>              <td class="syl_add_tdOne">预测结果</td>               <td class="syl_add_tdTwo">结果解释</td>                <td class="syl_add_tdThree">当前赔率</td>                 <td class="syl_add_tdThree">请选择</td>                  <td class="syl_add_tdOne">竞猜</td>                </tr></table>            </HeaderTemplate>                            <ItemTemplate>                   <table class="sanyaolingTable" style=" border-collapse:collapse; color:#515151; "><tr>              <td class="syl_add_tdOne">                  <asp:Label ID="lblresult" runat="server" Text='<%#Eval("Guess_310_Child_Result") %>'></asp:Label></td>               <td class="syl_add_tdTwo">                   <asp:Label ID="lblExplanation" runat="server" Text='<%#Eval("Guess_310_Child_Explanation") %>'></asp:Label></td>                <td class="syl_add_tdThree">                    <asp:Label ID="lblpeilv" runat="server" Text=""></asp:Label></td>                 <td class="syl_add_tdThree">                                                   <input name="CI" id="CI<%#Eval("Guess_310_Child_Result") %>" type="checkbox" value='<%#Eval("Guess_310_Child_Result") %>'                     onclick="chCI('<%#Eval("Guess_310_Child_Result") %>');"/>                 <asp:Label ID="lblqishu" runat="server" Text='<%#Eval("Guess_310_Child_QiShu") %>' Visible="false"></asp:Label>                    </td>                  <td class="syl_add_tdOne">                  <input  id="<%#Eval("Guess_310_Child_Result") %>" name="SMONEY" type="text"  size="15" value="0"                    onkeyup="if(event.keyCode !=37 && event.keyCode != 39) value=value.replace(/\D/g,'');fo('<%#Eval("Guess_310_Child_Result") %>');"                    onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/\D/g,''))"                    onclick="chCI('<%#Eval("Guess_310_Child_Result") %>');"/>                                     </td>                </tr></table>                </ItemTemplate>                                                       </asp:Repeater>           <table class="sanyaolingTable" style=" border-collapse:collapse; color:#515151;"><tr>             <td colspan="5">               我的总竞猜额:<input id="SMONEYSUM" name="SMONEYSUM"  type="text" readonly="readonly" value="0" /></td>                               </tr>                <tr>             <td colspan="5">                 <asp:Button ID="btnOK" runat="server" Text="确认" onclick="btnOK_Click" /></td>                               </tr>                </table>            后台:  protected void rpt310GuessAdd_ItemDataBound(object sender, RepeaterItemEventArgs e)    {//这里如何获取ck和SMONEY的值} protected void btnOK_Click(object sender, EventArgs e)    {        HtmlInputCheckBox ck;        //一个是ck        for (int i = 0; i < rpt310GuessAdd.Items.Count; i++)        {            ck = (HtmlInputCheckBox)rpt310GuessAdd.Items[i].FindControl("CI");            if (ck.Checked)            {                //查找SMONEY的值            }        }    }注释:如果我加个runat="server"就报错了,,就说:服务器标记的格式不正确,,,求解啊
  相关解决方案