【问题标题】:append textbox next to label in zend form以zend形式在标签旁边附加文本框
【发布时间】:2010-11-17 05:37:20
【问题描述】:

我正在使用 zend 框架。我为表单添加了一个新的复选框元素。带有值的示例复选框

abc xyz

当一个复选框被选中时,我想在每个选中的复选框旁边附加一个文本框(在标签标签关闭之后)。我正在尝试为此目的使用 jquery。任何人都可以在这个问题上帮助我。

【问题讨论】:

    标签: jquery zend-framework zend-form append


    【解决方案1】:

    以下函数在选中复选框时在每个复选框后添加一个新的文本输入,并在取消选中复选框时删除文本输入。文本输入的名称基于复选框的名称。

    jQuery(function($){
      var key = 'checkbox-master';
      $('input:checkbox').click(function(){
        var self = $(this);
        var next = self.next();
        if (this.checked){
          if (next.data(key)!=this){
            var n = this.name+'-text';
            self.after($('<input type="text" name="'+n+'">').data(key,this););
          }
        }else{
          if (next.data(key)==this) next.remove();
        }
      });
    });
    

    我想知道您是否真的想要这个,而不是仅仅动态显示和隐藏一些具有您想要的名称的预先创建的文本输入。假设文本输入总是紧跟在代码中的复选框之后,那就更简洁了:

    jQuery(function($){
      $('input:checkbox').click(function(){
        $(this).next()[this.checked ? 'show' : 'hide']();
      });
    });
    

    【讨论】:

      猜你喜欢
      • 2018-06-22
      • 2011-09-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-19
      • 2021-02-05
      • 2021-06-01
      • 1970-01-01
      相关资源
      最近更新 更多