本文整理匯總了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.');
}