我应该在这段代码中修改什么。
$this->addDisplayGroup($groupInputs, 'group_'.$i,
array('attribs'=>array('class'=>'fieldset_group')));
在fieldset中添加新的html标记,如:
<span class="delete_fieldset" onclick="foo()">[X]</span>
或者如果可能的话:
<span class="delete_fieldset_$i" onclick="foo($i)">[X]</span>
答案 0 :(得分:0)
我不确定你的问题 可能是这段代码可以帮到你:
// add a Zend_Form_Element_Note (Zend 1.12)
$newtag = new Zend_Form_Element_Note('span_elt', array('value' => '<span class="delete_fieldset_'. $i .'" onclick="foo(' . $i . ')">[X]</span>'));
// Remove decorators to have only span tag
$newtag->removeDecorator('HtmlTag');
$newtag->removeDecorator('Label');
// add $newtag in your code
$this->addDisplayGroup(array_merge(array($newtag), $groupInputs),
'group_'.$i,
array('attribs'=>array('class'=>'fieldset_group')));
我希望它能帮到你
答案 1 :(得分:0)
另一种方法是使用这样的javascript:
var attr_fieldset = "";
var num_fielset = 0;
var elt_fieldset = null;
// get all fieldsets
var list_fieldset = document.getElementsByClassName('fieldset_group');
for (var i = 0; i < list_fieldset.length; i++) {
// to get one fieldset
elt_fieldset = list_fieldset[i];
// to get $i
attr_fieldset = elt_fieldset.id.split("_");
num_fielset = attr_fieldset[1]; // (num_fielset = $i)
// create span element
var new_span = document.createElement("span");
new_span.className = 'delete_fieldset_' + num_fielset;
new_span.setAttribute('onclick', 'foo(' + num_fielset + ')');
new_span.innerHTML = '[X]';
// span element is the first child of the fieldset
elt_fieldset.insertBefore(new_span, elt_fieldset.firstChild);
}
如果您想在字段集的其他元素之后使用span元素,请替换
elt_fieldset.insertBefore(new_span, elt_fieldset.firstChild);
通过
elt_fieldset.appendChild(new_span);
我希望它会对你有所帮助。