javascript學習筆記—簡單的動態選擇收件者/連絡人

來源:互聯網
上載者:User

收件者.html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head>  <title>收件者</title>  <meta name="Generator" content="EditPlus">  <meta name="Author" content="">  <meta name="Keywords" content="">  <meta name="Description" content="">  <script type="text/javascript">function showContact(){//用變數接收返回的連絡人清單。注意只有強制回應視窗才能有傳回值!var returnValue = window.showModalDialog("連絡人清單.html","連絡人清單","dialogWidth:500px;dialogHeight:400px");var txt = document.getElementById("name");txt.value = returnValue; //給收件者文字框賦值}  </script> </head> <body><h1>發送訊息/郵件</h1>收件者:<input type="text" id="name" /><input type="button" value="選擇連絡人" onclick="showContact()" /> </body></html>

連絡人清單.html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head>  <title>連絡人清單</title>  <meta name="Generator" content="EditPlus">  <meta name="Author" content="">  <meta name="Keywords" content="">  <meta name="Description" content="">  <style type="text/css">table{border:1px solid green;border-collapse:collapse;width:400px;text-align:center;}table th,td{border:1px solid green;}</style>  <script type="text/javascript">function confirmContact(){var ck = document.getElementsByName("contact");var contactArr = check();if(ck.length){window.returnValue = contactArr.join(); //如果選中連絡人,就將連絡人返回window.close(); //關閉表單}else{alert("請選擇一個連絡人"); //如果沒有選中,就提示選擇}}//將選擇的連絡人放到集合裡function check(){var ck = document.getElementsByName("contact");var arr = [];for(var i=0;i<ck.length;i++){if(ck[i].checked){arr.push(ck[i].value);}}return arr;}  </script> </head> <body>  <h3>選擇連絡人</h3><table><tr><th>選擇</th><th>編號</th><th>姓名</th></tr><tr><td><input type="checkbox" name="contact" value="張龍" /></td><td>1</td><td>張龍</td></tr><tr><td><input type="checkbox" name="contact" value="趙虎" /></td><td>2</td><td>趙虎</td></tr><tr><td><input type="checkbox" name="contact" value="王朝" /></td><td>3</td><td>王朝</td></tr><tr><td><input type="checkbox" name="contact" value="馬漢" /></td><td>4</td><td>馬漢</td></tr><tr><td colspan="3"><input type="button" value="確定" onclick="confirmContact();" /></td></tr></table> </body></html>

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.