ȸ¿ø°¡ÀԡžÆÀ̵ð/ºñ¹øã±â
ȨÀ¸·Î


SelectBox Ŭ·¡½ºÀÔ´Ï´Ù
12³â Àü
php5¿ëÀÔ´Ï´Ù

<?php
class SelectBox{
    
    private  $name;
    private  $selectedIndex;
        private  $selectedFromValue;

    private  $attribute;
    private $option = array();
    
    public function __construct($name, $attribute=""){
        $this->name = $name;
        $this->attribute = $attribute;
    }
    
    public function __get($name){
        try{
            $this->checkProperty($name);
            return $this->$name;
        }catch(Exception $e){
            echo $e->getMessage();
        }
    }
    
    public function __set($name, $value){
        try{
            $this->checkProperty($name);
            $this->$name = $value;
        }catch(Exception $e){
            echo $e->getMessage();
        }
    }
    
    public function add($value, $text){
        $this->option[$value] = $text;
    }
    
    public function getTag(){
        $i=0;
        $str = "<select name='".$this->name."' ".$this->attribute.">\n";
        foreach($this->option as $key=>$value){
            if($this->selectedIndex == $i) $selected = " selected='selected'";
            else if($this->selectedFromValue == $key) $selected = " selected='selected'";
            else $selected = "";
            $str .= "<option value='".$key."'".$selected.">".$value."</option>\n";
            $i++;
        }
        $str .= "</select>";
        return $str;
    }
    
    private function checkProperty($name){
        if(!property_exists(__CLASS__, $name)){
            throw new Exception('Á¸ÀçÇÏÁö ¾Ê´Â Property['.$name.']¸¦ È£ÃâÇÏ¿´½À´Ï´Ù<br />');
        }
    }
}
?>


<»ç¿ë¹ý>
$select = new SelectBox('superUser', 'style="color:#ff00ff"');
$select->selectedIndex = 1; //¼±ÅÃµÈ »óÅÂÀÇ option À妽º
$select->add('admin', '°ü¸®ÀÚ');
$select->add('master', 'ºÎ°ü¸®ÀÚ');
$select->add('guest', '¼Õ´Ô');
echo $select->getTag();
ÃßõÃßõ : 584 Ãßõ ¸ñ·Ï
¹øÈ£ Á¦¸ñ
198
Input ¹Ú½º¿¡ »ç¶óÁö´Â ¹è°æ ³Ö±â
197
ºÎ¸ðdom ÀÇ ³ÐÀÌ¿¡ µû¶ó ÀÚµ¿À¸·Î ³ÐÀÌ Á¶ÀýÇϱâ
196
À̹ÌÁö°¡ Ŭ °æ¿ì Å×À̺íÀÌ ´Ã¾î³µ´Ù°¡ ÁÙ¾îµé¶§
195
from ű×ÀÇ ÀÌÇØ
194
÷ºÎ¸ÞÀÏ º¸³»±â
193
select multiple ÀÌ¿ëÇÑ ´ÙÁß°ª ¹Þ¾Æ¿À±â
SelectBox Ŭ·¡½ºÀÔ´Ï´Ù
191
°ü¸®ÀÚ ¹× ȸ¿øÀÇ ÆäÀÌÁö Á¢±Ù ±ÇÇÑ °£´Ü±¸Çö
190
FIELDSET ű׸¦ ÀÌ¿ëÇÏ¸é ¶§¿¡ µû¶ó ±ò²ûÇÑ Å×À̺íÀ» ¸¸µé ¼ö ÀÖ´Ù
189
overflow : hidden , text-overflow : ellipsis (±ÛÀÇ ±æÀÌ°¡ Ä­ÀÇ ±æÀ̸¦ ³Ñ¾î°¥ °æ¿ì ... ·Î ´ëü )
188
±ÝÁö ±ÝÄ¢¾î ºÒ·®´Ü¾î ÇÊÅ͸µ
187
?º¯¼ö=ÀԷ°ª&º¯¼ö=ÀԷ°ª ÀÌ·±½ÄÀ¸·Î ÀÚ¹Ù½ºÅ©¸³Æ®·Î cgi¾øÀÌ °ª ³Ñ°ÜÁÖ±â
186
È­¸é¿¡ ¿ÏÀüÈ÷ °íÁ¤µÈ ¹è³Ê
185
¾÷·Îµå È®ÀåÀÚ Ã¼Å©Çϱâ
184
input¹Ú½º¿¡ °ªÀÌ µé¾î¿ÀÀÚ ¸¶ÀÚ ÇØ´çµÇ´Â°ª Ãâ·Â
183
iexplore.exe ´ÜÃà ¸í·É
182
textarea ¹öÆ°À¸·Î ´Ã¸®°í ÁÙÀ̱â
181
textarea Åõ¸íÇÏ°Ô ¸¸µé±â
180
selectÀÇ ¼±ÅÃµÈ ¿É¼Ç°ªÀ» input ¶Ç´Â text ¹Ú½º¿¡ °ª ³Ñ±â±â | ÀÚ¹Ù½ºÅ©¸³Æ®
179
Æû¿¡ ÀÖ´Â ³»¿ëÀ» ¶È°°ÀÌ º¹»çÇØ ÁÖ´Â ½ºÅ©¸³Æ® 1
178
Æû¿¡ ÀÖ´Â ³»¿ëÀ» ¶È°°ÀÌ º¹»çÇØ ÁÖ´Â ½ºÅ©¸³Æ® 2
177
FIELDSET ű×
176
¼¿·ºÆ® ¹Ú½º ¼±Åýà ¼±Åà ¿É¼Çº¸¿©ÁÖ±â
175
div Áٹٲްú ÁÙ¹Ù²Þ ¹æÁö
174
HTML CSS ¿¡¼­ ul li ºí¸´, ±âÈ£, Á¡ ¾ø¾Ö±â
173
TABLEÀÇ TD °íÁ¤/¹è°æÀ̹ÌÁö °íÁ¤ÇÏ´Â ¹ý
172
Textarea ¼Ó¼º
171
css list-style Á¤¸®
170
border °¡ incide°¡ ¾ÈµÉ°æ¿ì
169
¼¿·ºÆ® ¹Ú½º ¼±Åýà ¼±Åà ¿É¼Çº¸¿©ÁÖ±â
¸ñ·Ï
¹ÂÁ÷Æ®·ÎÆ® ºÎ»ê±¤¿ª½Ã ºÎ»êÁø±¸ °¡¾ßµ¿ ¤Ó °³ÀÎÁ¤º¸Ãë±Þ¹æħ
Copyright ¨Ï musictrot All rights reserved.