本文介绍了PHP-如果下拉选择=的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我将如何基于下拉列表选择创建条件语句?
How would I go about creating a conditional statement based on a dropdown list selection?
让我们说我们有一个包含以下条目的下拉列表:
Lets say we have a dropdown list with entries:
Alpha
Bravo
Charlie
Other
我想创建一个条件语句,如果 Other
是下拉菜单中当前选择的条目,我想回显一个换行符,说明如果为其他,请指定
。但是,如果不是当前选择的条目,那么我就不想填充该字符串。
I want to create a conditional statement where if Other
is the currently selected entry from the dropdown, I want to echo a newline stating If Other, Please Specify
. But if it isn't the currently selected entry, I don't want that string to populate.
推荐答案
在PHP中
<select id="conditions" name="conditions">
<option></option>
<?php
foreach($option in $optionList){
echo "<option value=$option ";
if($_REQUEST["conditions"] == $option){
echo 'selected="selected"';
}
echo " > $option </option>";
}
echo "</select>";
if($_REQUEST["conditions"] == "Other"){
echo '<div id="specify" style="display:block">If Other, Please Specify</div>';
}else{
echo '<div id="specify" style="display:hidden">If Other, Please Specify</div>';
}
?>
在jQuery的客户端中
In jQuery for client side
<script>
$('#conditions').change(function(){
if($(this).val() == "Other"){
$('#specify').show();
}else{
$('#specify').hide();
}
});
</script>
这篇关于PHP-如果下拉选择=的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!