简体   繁体   English

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

[英]Show/Hide Select Option Based on the Type of User

I want to show/hide option from a select drop-down for free user & paid user form a php session value.我想从 select 下拉列表中显示/隐藏选项,以获取免费用户和付费用户的 php session 值。

   <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>

If如果

$_SESSION['mytype']= freeuser;

then hide option c1 & c2 & show c3 & c4 if然后隐藏选项 c1 & c2 & 显示 c3 & c4 if

$_SESSION['mytype']= paiduser;

then hide c3, c4 & show c1, c2然后隐藏 c3、c4 并显示 c1、c2

How can I achieve this?我怎样才能做到这一点?

   <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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM