我想将文本框值与下拉列表的选项值进行比较。
如果它们相同,则应出现警告框。
问问题
1839 次
2 回答
1
<input type="text" name="textbox" />
<select name="selectvalue">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
<script>
$("select[name=selectvalue]").change(function(){
if( $(this).val() == $("input[name=textbox]").val() )
alert("Value is same!!!");
})
</script>
您也可以在提交时或您想要的任何时间触发此检查。您没有提及何时需要警报。更改选择值或更改输入文本框值或单击按钮。
于 2013-10-11T07:59:05.260 回答
-3
// html code
<input type="text" id="textboxID" value="1" />
<select id="selectID">
<option value="1" selected>First</option>
</select>
// the script
<script type="text/javascript">
if ($("#textboxID").val() === $("#selectID").val())
alert("The values are equal.");
</script>
于 2013-10-11T07:52:36.027 回答