【发布时间】:2023-04-09 04:43:02
【问题描述】:
我有一些情况下的代码要先检查,然后代码应该根据它执行。我的代码有
<?php if($this->Session->read('Auth.User.id')==''){ ?>
<input class="profilebtn" type="button" style="width:100px !important; margin-top: 1px;" value="Start now" onclick="javascript:register_popup();">
<input class="profilebtn" type="button" style="width:100px !important; margin-top: 1px;" value="Start now" onclick="javascript:submitPlan(2);">
<input class="profilebtn" type="button" style="width:100px !important; margin-top: 1px;" value="Start now" onclick="javascript:submitPlan(3);">
<?php } elseif($this->Session->read('Auth.User.id')!='' && $this->Session->read('Auth.User.role_id')=='3' && isset($this->data['User']['plan_type']) && $this->data['User']['plan_type']=='A'){ ?>
<input class="profilebtn" type="button" style="width:100px !important; margin-top: 1px;" value="Your plan" onclick="javascript:register_popup();">
<input class="profilebtn" type="button" style="width:100px !important; margin-top: 1px;" value="Start now" onclick="javascript:submitPlan(2);">
<input class="profilebtn" type="button" style="width:100px !important; margin-top: 1px;" value="Start now" onclick="javascript:submitPlan(3);">
<?php } elseif($this->Session->read('Auth.User.id')!='' && $this->Session->read('Auth.User.role_id')=='3' && $this->data['User']['plan_type']=='B'){ ?>
<input class="profilebtn" type="button" style="width:100px !important; margin-top: 1px;" value="Start now" onclick="javascript:register_popup();">
<input class="profilebtn" type="button" style="width:100px !important; margin-top: 1px;" value="Your plan " onclick="javascript:submitPlan(2);">
<input class="profilebtn" type="button" style="width:100px !important; margin-top: 1px;" value="Start now" onclick="javascript:submitPlan(3);">
<?php } else{?>
<input class="profilebtn" type="button" style="width:100px !important; margin-top: 1px;" value="Start now" onclick="javascript:register_popup();">
<input class="profilebtn" type="button" style="width:100px !important; margin-top: 1px;" value="Start now" onclick="javascript:submitPlan(2);">
<input class="profilebtn" type="button" style="width:100px !important; margin-top: 1px;" value="Your plan" onclick="javascript:submitPlan(3);">
<?php } ?>
所以我在每种情况下都有 3 个按钮,因此根据用户已经计划,我想将按钮值从现在开始更改为您的计划和休息 2 按钮应该有立即开始选项。所以在这段代码中发生了什么,它检查条件是否不匹配然后直接执行 else 而不检查我想首先检查的 else if 部分。
【问题讨论】:
-
var_dump($this->data['User']['plan_type']);你看到了什么? -
就是这么说的:您可以在此之前在一些代码中设置按钮文本,并且您不会只有一组按钮,例如
<input type="button" value="<?= $button_text['A'] ?>" onclick="register_popup()">等。(顺便说一句,那些内联样式作为 CSS 中的#containerId input.profilebtn规则可能会更好。而且您不需要在 onclick 属性中使用javascript:。)
标签: php html cakephp-1.3