Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用javascript隐藏Zend元素标签_Javascript_Jquery_Zend Framework - Fatal编程技术网

如何使用javascript隐藏Zend元素标签

如何使用javascript隐藏Zend元素标签,javascript,jquery,zend-framework,Javascript,Jquery,Zend Framework,嗨,我有一个脚本,隐藏和显示哪个选择元素将被渲染取决于选择下拉列表的值 function testOnClick(){ var e = document.getElementById("role"); var selectValue = e.options[e.selectedIndex].value; alert(selectValue); if(selectValue == 1) { // $("#item").toggle();

嗨,我有一个脚本,隐藏和显示哪个选择元素将被渲染取决于选择下拉列表的值

function testOnClick(){ 
  var e = document.getElementById("role");

  var selectValue = e.options[e.selectedIndex].value;

  alert(selectValue);
  if(selectValue == 1)
  {       
     // $("#item").toggle();
      $("#sub_unit").show();
      $("#sub_unit_dropdown").hide();
      $('#sub_unit_dropdown').parent().children().hide()    
    }
  else
  {
      $("#sub_unit").hide();
      $('#sub_unit').parent().children().hide()
      $("#sub_unit_dropdown").show();
      }     
}

下面是zend元素

 $this->add(array(
            'name' => 'role',
                'id'   => 'role',
            'type' => 'Zend\Form\Element\Select',
            'options' => array(
                'label' => 'Role',              
                'empty_option' => '(Please select)',
                'value_options' => array(
                    '1' => 'Manager',
                    '2' => 'Employee',
                ),
            ),
        ));

        $this->add(array(
            'name' => 'status',
            'type' => 'Zend\Form\Element\Select',
            'options' => array(
                'label' => 'Status',
                'value_options' => array(
                    '1' => 'Active',
                    '2' => 'Inactive',
                ),
            ),
        ));

        $this->add(array(
            'name' => 'sub_unit',
            'id'   => 'sub_unit',               
            'type' => 'Zend\Form\Element\Select',
            'options' => array(
                'label' => 'Sub Unit / Team',
                'value_options' => $this->getOptionsForSubUnit(),
                'description' => 'Hold down the control (ctrl) button to select multiple options',
            ),
            'attributes' => array(
                'multiple' => true,
                'size'     => 12,
            ),
        ));

          $this->add(array(
            'name'       => 'sub_unit_dropdown',
            'id'        => 'sub_unit_dropdown',
            'type'       => 'Zend\Form\Element\Select',
            'options'    => array(
                'label' => 'Sub Unit / Team',
                'value_options' => $this->getOptionsForSubUnit(),
            ),
            'attributes' => array(
                'size'     => 12,
                'class' => 'input-medium'
            ),
        ));
它工作正常,隐藏并显示将隐藏或显示的选择元素,但问题是隐藏选择元素的标签仍然可见。 如何将其与需要隐藏的select元素一起隐藏


TIA

请测试这是否有效

$this->add(array(
        'name'       => 'sub_unit_dropdown',
        'id'        => 'sub_unit_dropdown',
        'type'       => 'Zend\Form\Element\Select',
        'options'    => array(
            'label' => 'Sub Unit / Team',
            'label_attributes' => array('class' => 'hidethelabel'),
            'value_options' => $this->getOptionsForSubUnit(),
        ),
        'attributes' => array(
            'size'     => 12,
            'class' => 'input-medium'
        ),
    ));
基本上我认为可以添加一个类或id

'label_attributes'=>数组('class'=>'hidethelabel')

并在脚本中使用该id/类来隐藏标签


只是一个想法。

共享您的html代码,让我们知道您要隐藏哪个标签??它们是zend元素这些是我编辑的问题的zend元素,所以您要隐藏/显示“子单位/团队”标签。我说得对吗?你可以试试
$(“#sub_unit”).prev('label').hide()
。我假设
label
标记正好出现在输入元素之前。希望这对你有帮助。嗨,谢谢,它工作得很好,但现在我的问题是描述,我也尝试给它类属性,但它不起作用。尝试搜索如何在zend form创建的描述元素上添加属性,你应该会找到答案。如果不发布其他问题,我们将试一试