📄 htmlselectelementimpl.java
字号:
/** * org/ozone-db/xml/dom/html/HTMLSelectElementImpl.java * * The contents of this file are subject to the OpenXML Public * License Version 1.0; you may not use this file except in compliance * with the License. You may obtain a copy of the License at * http://www.openxml.org/license.html * * THIS SOFTWARE IS DISTRIBUTED ON AN "AS IS" BASIS WITHOUT WARRANTY * OF ANY KIND, EITHER EXPRESSED OR IMPLIED. THE INITIAL DEVELOPER * AND ALL CONTRIBUTORS SHALL NOT BE LIABLE FOR ANY DAMAGES AS A * RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS * DERIVATIVES. SEE THE LICENSE FOR THE SPECIFIC LANGUAGE GOVERNING * RIGHTS AND LIMITATIONS UNDER THE LICENSE. * * The Initial Developer of this code under the License is Assaf Arkin. * Portions created by Assaf Arkin are Copyright (C) 1998, 1999. * All Rights Reserved. */package org.ozoneDB.xml.dom.html;import org.ozoneDB.xml.dom.*;import org.w3c.dom.*;import org.w3c.dom.html.*;/** * @version $Revision: 1.3 $ $Date: 2000/10/28 16:55:24 $ * @author <a href="mailto:arkin@trendline.co.il">Assaf Arkin</a> * @see org.w3c.dom.html.HTMLSelectElement * @see ElementImpl */public final class HTMLSelectElementImpl extends HTMLElementImpl implements HTMLSelectElement, HTMLFormControl { public String getType() { return getAttribute( "type" ); } public String getValue() { return getAttribute( "value" ); } public void setValue( String value ) { setAttribute( "value", value ); } public int getSelectedIndex() { NodeList options; int i; // Use getElementsByTagName() which creates a snapshot of all the // OPTION elements under this SELECT. Access to the returned NodeList // is very fast and the snapshot solves many synchronization problems. // Locate the first selected OPTION and return its index. Note that // the OPTION might be under an OPTGROUP. options = getElementsByTagName( "OPTION" ); for (i = 0; i < options.getLength(); ++i) { if (((HTMLOptionElement)options.item( i )).getSelected()) { return i; } } return -1; } public void setSelectedIndex( int selectedIndex ) { NodeList options; int i; // Use getElementsByTagName() which creates a snapshot of all the // OPTION elements under this SELECT. Access to the returned NodeList // is very fast and the snapshot solves many synchronization problems. // Change the select so all OPTIONs are off, except for the // selectIndex-th one. options = getElementsByTagName( "OPTION" ); for (i = 0; i < options.getLength(); ++i) { ((HTMLOptionElementImpl)options.item( i )).setSelected( i == selectedIndex ); } } public HTMLCollection getOptions() { if (_options == null) { _options = new HTMLCollectionImpl( this, HTMLCollectionImpl.OPTION ); } return _options; } public int getLength() { return getOptions().getLength(); } public boolean getDisabled() { return getAttribute( "disabled" ) != null; } public void setDisabled( boolean disabled ) { setAttribute( "disabled", disabled ? "" : null ); } public boolean getMultiple() { return getAttribute( "multiple" ) != null; } public void setMultiple( boolean multiple ) { setAttribute( "multiple", multiple ? "" : null ); } public String getName() { return getAttribute( "name" ); } public void setName( String name ) { setAttribute( "name", name ); } public int getSize() { return toInteger( getAttribute( "size" ) ); } public void setSize( int size ) { setAttribute( "size", String.valueOf( size ) ); } public int getTabIndex() { return toInteger( getAttribute( "tabindex" ) ); } public void setTabIndex( int tabIndex ) { setAttribute( "tabindex", String.valueOf( tabIndex ) ); } public void add( HTMLElement element, HTMLElement before ) { insertBefore( element, before ); } public void remove( int index ) { NodeList options; Node removed; // Use getElementsByTagName() which creates a snapshot of all the // OPTION elements under this SELECT. Access to the returned NodeList // is very fast and the snapshot solves many synchronization problems. // Remove the indexed OPTION from it's parent, this might be this // SELECT or an OPTGROUP. options = getElementsByTagName( "OPTION" ); removed = options.item( index ); if (removed != null) { removed.getParentNode().removeChild( removed ); } } public void blur() { // No scripting in server-side DOM. This method is moot. } public void focus() { // No scripting in server-side DOM. This method is moot. } /** * Constructor requires owner document. * * @param owner The owner HTML document */ public HTMLSelectElementImpl( HTMLDocumentImpl owner, String name ) { super( owner, "SELECT" ); } private HTMLCollection _options; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -