Yesterday, in the project encountered the cause of the option to show the exception, screenshot as follows:
Firefox with CSS control after the effect
CSS doesn't work in chrome and IE
Code:
The code is as follows |
Copy Code |
<div class= "Controls" > <select name= "Ksname" id= "Ksname" > <?php while (!! $rowDK = Fetchassoc ($resultDK)) { ?> <optgroup label= "<?php echo $rowDK [' name '];?>" > <?php $resultKS = Querydb ("Select Table_dake.id,table_keshi.sid,table_keshi.name from Table_dake,table_keshi Where Table_dake.name= ' {$rowDK [' name ']} ' and Table_keshi.sid=table_dake.id '); while (!! $rowKS = Fetchassoc ($resultKS)) { ?> <option value = "<?php echo $rowKS [' name '];?>" ><?php echo $rowKS [' name '];?></option>
<?php </optgroup> } } Free ($resultDK); Free ($resultKS); ?> </select> </div> |
Debugging for a long time, online also found a way, and ultimately no fruit, as long as to consult Daniel. Daniel suggested that I check the source code, is the style changed? The Select section of this code does not have any style, how can it be more? After reading the source code, the style does not have much, but after each option more than one </optgroup> back to look at the code, just understand, I put </optgroup> written in the inner loop, according to my logic, should be put outside the loop. After the adjustment, everything is OK.
Add one:
A select is a very important representation of a list-type element. Sum up some of his writing notes.
1. With regard to innerHTML, in IE do not support the form of innerHTML to add option options, Firefox,chrome is supported.
2. Add option, use Ele.options.add (option), but here option can be constructed in the form of new option (Text,value), or it can be done by
The native function is created by the Document.createelement function. In addition, the Add method will not overwrite the previous. option cannot be in the form of HTML.
3. Select a particular option in the way ele.value = Option.value; Conversely, if the current is a specific option,
Then the value of ele must be option.value;
4. There is another way to get the value of the selected option (I don't recommend it) Ele.options[ele.selectedindex].value, this is a little bit more complicated, but it's a matter of fact
This is the concept of an index for list items of list elements.
The code is as follows |
Copy Code |
<! DOCTYPE html> <meta http-equiv= "Content-type" content= "text/html;charset=gb2312"/> <title></title>
<body> <select name= "test" id= "Test" > <option value= "Etcyby" >hehe</option> </select> <script type= "Text/javascript" > function $ (ID) { return document.getElementById (ID); } function render () { for (var i = 0; i < 100;i++) { var ele = document.createelement (' option '); Ele.text = ' etcyby ' + i; Ele.value = i; $ (' test '). Options.add (Ele); } $ (' test '). Value = ' 99 ' Alert ($ (' test '). options[$ (' Test '). Selectedindex].value); } function Render2 () { $ (' test '). InnerHTML = ' <option value= ' etcyby ' >hehe</option> '; } Render (); </script> </body> |