select-1-dynamic.html 906 B

1234567891011121314151617181920212223242526272829303132
  1. <!DOCTYPE html>
  2. <html>
  3. <select style="position: relative" size=4>
  4. <option>bar</option>
  5. </select>
  6. <select style="position: relative">
  7. <option>bar</option>
  8. </select>
  9. <script>
  10. function injectAbsPosKid(s) {
  11. var option = document.createElement("option");
  12. option.appendChild(document.createTextNode("foo"));
  13. option.style.position = "absolute";
  14. option.style.top = "100px";
  15. s.insertBefore(option, s.firstChild);
  16. var div = document.createElement("div");
  17. div.appendChild(document.createTextNode("bar"));
  18. div.style.position = "absolute";
  19. div.style.top = "200px";
  20. s.appendChild(div);
  21. }
  22. onload = function() {
  23. var s1 = document.querySelectorAll("select")[0];
  24. var s2 = document.querySelectorAll("select")[1];
  25. injectAbsPosKid(s1);
  26. injectAbsPosKid(s2);
  27. s2.selectedIndex = 0;
  28. };
  29. </script>
  30. </html>