【问题标题】:how to compare radio button values with textbox values in asp.net如何将单选按钮值与asp.net中的文本框值进行比较
【发布时间】:2010-12-22 05:50:32
【问题描述】:

我有四个单选按钮和一个文本框..我必须检查选定的单选按钮值是否等于文本框值..请帮助我

【问题讨论】:

  • 您将不得不为我们提供更多的工作...

标签: asp.net visual-studio-2008


【解决方案1】:
if(radioButtonList.SelectedValue == textBox1.Text.Trim())
{
   //your code goes here
}

【讨论】:

    【解决方案2】:

    textBox 不包含 Value 属性。

    
    if (!string.IsNullOrEmpty(RadioButtonList1.SelectedValue) &&
                    RadioButtonList1.SelectedValue.Equals(TextBox1.Text, StringComparison.Ordinal))
        {
            //your code goes here
        }
    

    【讨论】:

      【解决方案3】:

      嗯。你没有说明你想在哪里做这个比较,即客户端或服务器端。如果你想要它在服务器端,你可以更喜欢早期发布的答案,否则客户端使用 Jquery 尝试这个。

      <div>
          <input type='radio' name='rd' value='A'>
          <input type='radio' name='rd' value='B'>
          <input type='radio' name='rd' value='C'>
          <br />
          <asp:TextBox ID="txtName" runat="server"></asp:TextBox>
      </div>
      
      <script type="text/javascript" >
          $(document).ready(function(){
          $("input:radio[name='rd']").click(function(){
              if($(this).is(":checked"))
              {
                  if($.trim($(this).val()) == $.trim($("#txtName").val()))
                      alert("Yeah!I got matched value.");
                  else
                      alert("Oops!Not matched.");
              }
          });
      
          });
      </script>
      

      点击此链接:

      DEMO

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-12-13
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多