根据用户类型显示/隐藏选择选项

时间:2019-10-26 19:15:25

标签: javascript php jquery

我想从php会话值的免费用户和付费用户的选择下拉列表中显示/隐藏选项。

   <select id="book" name="book" style="display:none" onchange="update_session_value(this.value)">
        <option id = "c1" class="b1" value="A1">A1</option> 
        <option id = "c2" class="b1" value="A2">A2</option> 
        <option id = "c3" class="b2" value="A3">A3</option> 
        <option id = "c4"class="b2" value="A4">A4</option> 
    </select>

如果

$_SESSION['mytype']= freeuser;

然后隐藏选项c1和c2并显示c3和c4 如果

$_SESSION['mytype']= paiduser;

然后隐藏c3,c4和show c1,c2

我该如何实现?

1 个答案:

答案 0 :(得分:-2)

   <select id="book" name="book" style="display:none" onchange="update_session_value(this.value)">
<?php if ($_SESSION['mytype'] === 'paiduser') { ?>
        <option id = "c1" class="b1" value="A1">A1</option> 
        <option id = "c2" class="b1" value="A2">A2</option> 
<?php } else { ?>
        <option id = "c3" class="b2" value="A3">A3</option> 
        <option id = "c4"class="b2" value="A4">A4</option> 
<?php } ?>
    </select>