【发布时间】:2010-12-22 05:50:32
【问题描述】:
我有四个单选按钮和一个文本框..我必须检查选定的单选按钮值是否等于文本框值..请帮助我
【问题讨论】:
-
您将不得不为我们提供更多的工作...
标签: asp.net visual-studio-2008
我有四个单选按钮和一个文本框..我必须检查选定的单选按钮值是否等于文本框值..请帮助我
【问题讨论】:
标签: asp.net visual-studio-2008
if(radioButtonList.SelectedValue == textBox1.Text.Trim())
{
//your code goes here
}
【讨论】:
textBox 不包含 Value 属性。
if (!string.IsNullOrEmpty(RadioButtonList1.SelectedValue) &&
RadioButtonList1.SelectedValue.Equals(TextBox1.Text, StringComparison.Ordinal))
{
//your code goes here
}
【讨论】:
嗯。你没有说明你想在哪里做这个比较,即客户端或服务器端。如果你想要它在服务器端,你可以更喜欢早期发布的答案,否则客户端使用 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>
点击此链接:
【讨论】: