本文整理汇总了PHP中Element::setAttribute方法的典型用法代码示例。如果您正苦于以下问题:PHP Element::setAttribute方法的具体用法?PHP Element::setAttribute怎么用?PHP Element::setAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Element
的用法示例。
在下文中一共展示了Element::setAttribute方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setAttribute
public function setAttribute($key, $value)
{
if ('value' === $key) {
$this->selected = (int) $value;
}
parent::setAttribute($key, $value);
}
示例2: setAttribute
/**
* Handles the value attribute. If the "value" attribute is set,
* the option with the attribute's value is then selected.
* @param $name the name of the attribute
* @param $value the value of the attribute
*/
public function setAttribute($name, $value)
{
if (strtolower($name) == 'value') {
$this->setSelectedOption($value);
} else {
parent::setAttribute($name, $value);
}
}
示例3: setAttribute
/**
* Handles the special case of label. The label is the inner text of the <option> tag.
* @param $name The name of the attribute.
* @param $value The value of the attribute.
*/
public function setAttribute($name, $value)
{
if ($name == 'label') {
$this->setLabel((string) $value);
} else {
parent::setAttribute($name, $value);
}
}
示例4: addElement
public function addElement(Element $element)
{
$element->setForm($this);
//If the element doesn't have a specified id, a generic identifier is applied.
$id = $element->getAttribute("id");
$name = $element->getAttribute("name");
if (empty($id) && $name) {
$element->setAttribute("id", $name);
} elseif (empty($id)) {
$element->setAttribute("id", $this->attributes["id"] . "-element-" . sizeof($this->elements));
}
$this->elements[] = $element;
/*For ease-of-use, the form tag's encytype attribute is automatically set if the File element
class is added.*/
if ($element instanceof Element\File) {
$this->attributes["enctype"] = "multipart/form-data";
}
}
示例5: setAttribute
/**
* Adds the functionality of setting the 'value' to the textarea's inner {@link TextNode}.
* @param $attr the attribute name
* @param $value the attribute value
*/
public function setAttribute($attr, $value)
{
//value is the text node
//we add this for the sake of consistency amongst other form elements
if (strtolower($attr) == 'value') {
$this->setText($value);
} else {
parent::setAttribute($attr, $value);
}
}
示例6: testSetAttribute
/** Tests for {@link Element::setAttribute}. */
public function testSetAttribute()
{
$e = new Element('div');
$this->assertSame(0, count($e->getAttributes()), 'Set of attributes not empty for new Element.');
$e->setAttribute('lang', 'nl');
$a = $e->getAttributes();
$this->assertSame(1, count($a), 'Attribute not added to Element.');
$this->assertSame('nl', $a['lang'], 'Attribute value incorrect.');
$e->setAttribute('lang', 'nl-be');
$a = $e->getAttributes();
$this->assertSame(1, count($a), 'Attribute not replaced.');
$this->assertSame('nl-be', $a['lang'], 'Replaced attribute has incorrect value.');
}