Javascript 从Zend表单元素中删除id属性
我有:Javascript 从Zend表单元素中删除id属性,javascript,php,jquery,forms,zend-framework,Javascript,Php,Jquery,Forms,Zend Framework,我有: 但是当呈现选定的下拉列表时,它具有我不想要的id=“type”属性。我正在用JavaScript克隆这个元素,但在所有事件之后,它都无法正常工作。一旦克隆了元素,您可以重置/更改其id (在对其执行任何操作之前,即注入回dom) 简单装箱一个变量来保存克隆并更改其id属性。例如: $this->addElement('select', 'type', array( 'label' => 'Banner type', 'required' =&g
但是当呈现选定的
下拉列表时,它具有我不想要的id=“type”
属性。我正在用JavaScript克隆这个元素,但在所有事件之后,它都无法正常工作。一旦克隆了元素,您可以重置/更改其id
(在对其执行任何操作之前,即注入回dom)
简单装箱一个变量来保存克隆并更改其id
属性。例如:
$this->addElement('select', 'type', array(
'label' => 'Banner type',
'required' => true,
'multiOptions' => array(
'' => 'Please select',
'1' => 'Image',
'3' => 'Flash',
'4' => 'Html'
),
'value' => '',
));
您最好修改javascript(仅在克隆元素时更改id)
如果要使用ZF更改表单元素的结构,必须创建自己的select元素扩展Zend_form_element_select,然后创建自己的formSelect视图辅助对象扩展Zend_view_helper_formSelect并重写formSelect()
方法。请看下面我的评论:
$(function (){
var div = $('#myId');
console.log(div[0].id); //shows the element id
var newDiv = div.clone(); //clone the element
console.log(newDiv[0].id); //shows original element id
newDiv[0].id = "myNewId"; //change the id
console.log(newDiv[0].id); //shows 'myNewId'
});
$xhtml=”那么php呢?当我想通过php这样做的时候?
$xhtml = '<select'
. ' name="' . $this->view->escape($name) . '"'
. ' id="' . $this->view->escape($id) . '"' // remove this line
. $multiple
. $disabled
. $this->_htmlAttribs($attribs)
. ">\n ";