php 在 ZEND 的选择下拉列表中选择后的 Onchange 事件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28540414/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 23:55:44  来源:igfitidea点击:

Onchange event after selecting in select dropdown list in ZEND

phpzend-frameworkhtml-selectselectionchanged

提问by Dave

I have a view with a dropdown list using select tag and I want to how can i have an event or an onchange event after selecting a value in my dropdown.

我有一个使用 select 标签的下拉列表视图,我想在我的下拉列表中选择一个值后如何有一个事件或一个 onchange 事件。

here is my code in index.phtml

这是我在 index.phtml 中的代码

    <?php if (count($users)): ?>
    <table class="table table-hover">
    <thead>
    <tr>
        <th>Name</th>
        <th>E-mail</th>
        <th>Level</th>
        <th></th>
      </tr>
    </thead>
    <?php foreach ($users as $user): ?>
   <tr>
        <td><a href="<?php echo $this->url('user/edit', array('id' => $user->id)); ?>"><?php echo $this->escapeHtml($user->first_name . ' ' . $user->last_name); ?></a></td>
        <td><?php echo $this->escapeHtml($user->email); ?></td>
        <td>
            <select name="level">

            <?php $level = $this->escapeHtml($user->level); ?>

            <?php if ($level == 1): ?>
                 <option value="1" selected="selected">Administrator</option>
                 <option value="2">Manager</option>
                 <option value="3">HR Staff</option>
             <?php elseif ($level == 2): ?>
                 <option value="1" >Administrator</option>
                 <option value="2" selected="selected">Manager</option>
                 <option value="3">HR Staff</option>
               <?php elseif ($level == 3): ?>
                 <option value="1" >Administrator</option>
                 <option value="2" >Manager</option>
                 <option value="3" selected="selected">HR Staff</option>
                <?php endif; ?>
            </select>
        </td>
        <td style="text-align: right;">
            <a href="<?php echo $this->url('user/delete', array('id' => $user->id)); ?>" class="btn btn-mini btn-danger" rel="tooltip" title="Delete this user"><i class="icon-remove icon-white"></i></a>
        </td>
    </tr>
    <?php endforeach; ?>
    </table>
<?php else: ?>
<h3>There are no registered users available.</h3>
<?php endif; ?>

Thanks in Advance

提前致谢

回答by Nishit Maheta

create javascript function and put function in select box onchange event.

创建 javascript 函数并将函数放入选择框 onchange 事件中。

check working example on fiddle

检查小提琴上的工作示例

<script>
 function changeTest(obj){
    alert(obj.options[obj.selectedIndex].value);
  }
</script>

 <select name="level" onChange="changeTest(this)">
   <option value="1" selected="selected">Administrator</option>
             <option value="2">Manager</option>
             <option value="3">HR Staff</option>
 </select>