国产探花免费观看_亚洲丰满少妇自慰呻吟_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 全部選擇 提示:你可先修改部分代碼,再按運行]

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 施秉县| 偃师市| 邵阳县| 潼关县| 宽城| 新平| 台北市| 商河县| 封丘县| 奉化市| 府谷县| 固阳县| 轮台县| 阳曲县| 三门峡市| 乐亭县| 遂平县| 中江县| 杭锦后旗| 南开区| 儋州市| 仲巴县| 宣化县| 永德县| 延庆县| 夹江县| 姜堰市| 温州市| 靖宇县| 大姚县| 思南县| 呼和浩特市| 闵行区| 湟中县| 吴川市| 威海市| 西城区| 铁岭县| 乌恰县| 桐庐县| 宜兰县|