国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > JS > 正文

JS初學者實例教程(9):下拉菜單和鏈接屬性

2024-09-06 12:40:51
字體:
來源:轉載
供稿:網友
上一篇js教程學習了:js初學者實例教程(8):單選按鈕、復選按鈕 

實例九

本實例主要介紹了document對象讀取表單元素的使用(下拉菜單、鏈接屬性的使用)

<html>
<head>
<title>下拉菜單</title>
<script language="javascript">
function display()
{
 if(document.selectform.team.selectedindex==0) //判斷是否進行了選擇
 {
  alert("您沒有做選擇!");
 }
 else
 {
  var index = document.selectform.team.selectedindex; //讀出當前選項的下標
  alert("您選擇的球隊是:"+document.selectform.team.options[index].value);
 }
}
</script>
</head>
<body>
<div align="center">
  <form action="" method="post" name="selectform" id="selectform">
    <table width="70%"  border="0">
      <tr>
        <td>請選擇喜歡的球隊:</td>
      </tr>
      <tr>
        <td><select name="team">
          <option value="0">--未選擇--</option>
          <option value="巴塞羅那">巴塞羅那</option>
          <option value="ac米蘭">ac米蘭</option>
          <option value="尤文圖斯">尤文圖斯</option>
          <option value="曼徹斯特聯">曼徹斯特聯</option>
          <option value="切爾西">切爾西</option>
        </select></td>
      </tr>
      <tr>
        <td><input name="look" type="button" id="look" value="單擊查看" onclick="display()"></td>
      </tr>
    </table>
<a href="http://www.baidu.com" name="baidu" target="_blank">有問題百度一下</a>
<br><br>
<a href="http://www.google.com" name="google" target="_blank">google也可以</a><br><br>
<script language="javascript">
document.write("第一個連接的信息:<br>");
document.write("<b>href:</b>"+document.links[0].href+"<br>");
document.write("<b>pathname:</b>"+document.links[0].pathname+"<br>");
document.write("<b>port:</b>"+document.links[0].port+"<br>");
document.write("<b>protocol:</b>"+document.links[0].protocol+"<br>");
document.write("<b>target:</b>"+document.links[0].target+"<br>");
document.write("<br><br>");
document.write("第二個連接的信息:<br>");
document.write("<b>href:</b>"+document.links[1].href+"<br>");
document.write("<b>pathname:</b>"+document.links[1].pathname+"<br>");
document.write("<b>port:</b>"+document.links[1].port+"<br>");
document.write("<b>protocol:</b>"+document.links[1].protocol+"<br>");
document.write("<b>target:</b>"+document.links[1].target+"<br>");
</script>
  </form>
</div>
</body>
</html>

效果演示:


[ctrl+a 全部選擇 提示:你可先修改部分代碼,再按運行]

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 和平县| 乌鲁木齐市| 翼城县| 精河县| 抚州市| 朝阳市| 镇宁| 泗水县| 北票市| 江都市| 呼图壁县| 谷城县| 工布江达县| 华宁县| 云南省| 鄂州市| 昌黎县| 修水县| 周口市| 宁远县| 齐齐哈尔市| 石楼县| 闵行区| 泌阳县| 定西市| 通渭县| 丹东市| 罗山县| 建水县| 雷州市| 香格里拉县| 鄂伦春自治旗| 武邑县| 衡水市| 怀仁县| 安宁市| 榆林市| 翁牛特旗| 新乐市| 安仁县| 阳高县|