HTML DOM 对象属性(摘自W3school)

selectedIndex 属性可设置或返回下拉列表中被选选项的索引号。

语法 selectObject.selectedIndex=number
<html>
<head>
<script type="text/javascript">
function getIndex()
  {
  var x=document.getElementById("mySelect")
  alert(x.selectedIndex)
  }
</script>
</head>
<body>

<form>
Select your favorite fruit:
<select id="mySelect">
  <option>Apple</option>
  <option>Orange</option>
  <option>Pineapple</option>
  <option>Banana</option>
</select>
<br /><br />
<input type="button" onclick="getIndex()"
value="Alert index of selected option">
</form>

</body>
</html>

显示<option>的value值 没有设置的话默认从0开始

window.resizeTo

函数:window.resizeTo(width, height) 
作用:改变窗口大小到设定的宽和高 
参数:width - 宽度像素,必须设定的参数 
          height - 高度像素,可选参数 
这个高度和宽度指的是整个窗口外框的宽度和高度,包括窗口的标题栏、地址栏、状态栏、边框等等,而不是页面内容的高度和宽度。 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript">
function resizeWindow()
  {
  window.resizeTo(500,300)
  }
</script>
</head>
<body>

<input type="button" onclick="resizeWindow()"
value="窗口大小改变">

</body>
</html>

window.open(URL,name,features,replace)

URL一个可选的字符串,声明了要在新窗口中显示的文档的 URL。如果省略了这个参数,或者它的值是空字符串,那么新窗口就不会显示任何文档。

name一个可选的字符串,该字符串是一个由逗号分隔的特征列表,其中包括数字、字母和下划线,该字符声明了新窗口的名称。这个名称可以用作标记 <a> 和 <form> 的属性 target 的值。如果该参数指定了一个已经存在的窗口,那么 open() 方法就不再创建一个新窗口,而只是返回对指定窗口的引用。在这种情况下,features 将被忽略。

features一个可选的字符串,声明了新窗口要显示的标准浏览器的特征。如果省略该参数,新窗口将具有所有标准特征。在窗口特征这个表格中,我们对该字符串的格式进行了详细的说明。replace一个可选的布尔值。规定了装载到窗口的 URL 是在窗口的浏览历史中创建一个新条目,还是替换浏览历史中的当前条目。支持下面的值:

true - URL 替换浏览历史中的当前条目。false - URL 在浏览历史中创建新的条目。

  • <html>
    <head>
    <script type="text/javascript">
    function open_win() 
    {
    window.open("http://www.w3school.com.cn")
    }
    </script>
    </head>
    <body>
    
    <input type=button value="Open Window" onclick="open_win()" />
    
    </body>
    </html>

    不能与document.open()混淆,两者完全不同

    document.open(mimetype,replace)

  • mimetype 可选。规定正在写的文档的类型。默认值是 "text/html"。
    replace 可选。当此参数设置后,可引起新文档从父文档继承历史条目。
  • <html>
    <head>
    <script type="text/javascript">
    function createNewDoc()
      {
      var newDoc=document.open("text/html","replace");
      var txt="<html><body>Learning about the DOM is FUN!</body></html>";
      newDoc.write(txt);
      newDoc.close();
      }
    </script>
    </head>
    <body>
    
    <input type="button" value="Write to a new document"
    onclick="createNewDoc()">
    
    </body>
    </html>
原文地址:https://www.cnblogs.com/happinesshappy/p/4505377.html