【发布时间】:2020-08-10 18:15:20
【问题描述】:
实际上我是动态获得价值的。 when option value is null it will hide select tag> if option value is available the show select tag.
<select id="userList">
<option selected="selected" value="">Choose one</option>
<?php
foreach($_SESSION ["userList"] as $key => $value) { ?>
<option value="<?php echo $value; ?>"><?php echo $value; ?></option>
<?php
} ?>
</select>
----------
if ($("#userList").val() == NULL) {
$('#userList').hide();
} else {
$('#userList').show();
}
when option value is null it will hide select tag> if option value is available the show select tag.
【问题讨论】:
-
您检查控制台是否有错误?如
NULL is not defined。试试null -
@freedomn-m 是的,它显示...
-
当您第一次使用 php 添加选项时,您可以检查
$_SESSION ["userList"]是否为空,然后隐藏该选项,否则显示。
标签: javascript jquery