1: <script> <BR>2: var thisDate = new Date(); <BR>3: document.write(thisDate.toString()); <BR>4: </script>
30 指定日期的时区
1: <script> <BR>2: var myOffset = -2; <BR>3: var currentDate = new Date(); <BR>4: var userOffset = currentDate.getTimezoneOffset()/60; <BR>5: var timeZoneDifference = userOffset - myOffset; <BR>6: currentDate.setHours(currentDate.getHours() + timeZoneDifference); <BR>7: document.write(“The time and date in Central Europe is: “ + currentDate.toLocaleString()); <BR>8: </script>
31 设置日期输出格式
1: <script> <BR>2: var thisDate = new Date(); <BR>3: var thisTimeString = thisDate.getHours() + “:” + thisDate.getMinutes(); <BR>4: var thisDateString = thisDate.getFullYear() + “/” + thisDate.getMonth() + “/” + thisDate.getDate(); <BR>5: document.write(thisTimeString + “ on “ + thisDateString); <BR>6: </script>
32 读取URL参数
1: <script> <BR>2: var urlParts = document.URL.split(“?”); <BR>3: var parameterParts = urlParts[1].split(“&”); <BR>4: for (i = 0; i < parameterParts.length; i++) { <BR>5: var pairParts = parameterParts[i].split(“=”); <BR>6: var pairName = pairParts[0]; <BR>7: var pairValue = pairParts[1]; <BR>8: document.write(pairName + “ :“ +pairValue ); <BR>9: } <BR>10: </script>
你还以为HTML是无状态的么?
33 打开一个新的document对象
1: <script> <BR>2: function newDocument() { <BR>3: document.open(); <BR>4: document.write(“<p>This is a New Document.”); <BR>5: document.close(); <BR>6: } <BR>7: </script>
1: <script> <BR>2: function checkField(field) { <BR>3: if (field.value == “”) { <BR>4: window.alert(“You must enter a value in the field”); <BR>5: field.focus(); <BR>6: } <BR>7: } <BR>8: </script> 9:
50 验证Select项
1: function checkList(selection) { 2: if (selection.length == 0) { 3: window.alert(“You must make a selection from the list.”); 4: return false; 5: } 6: return true; 7: }
51 动态改变表单的action
1:
52 使用图像按钮
1: 6:
53 表单数据的加密
1: <script> <BR>2: <!-- <BR>3: function encrypt(item) { <BR>4: var newItem = ''; <BR>5: for (i=0; i < item.length; i++) { <BR>6: newItem += item.charCodeAt(i) + '.'; <BR>7: } <BR>8: return newItem; <BR>9: } <BR>10: function encryptForm(myForm) { <BR>11: for (i=0; i < myForm.elements.length; i++) { <BR>12: myForm.elements[i].value = encrypt(myForm.elements[i].value); <BR>13: } <BR>14: } <BR>15: <BR>16: //--> <BR>17: </script> 18:
JavaScript就这么回事5:窗口和框架
54 改变浏览器状态栏文字提示
1: <script> <BR>2: window.status = “A new status message”; <BR>3: </script>
55 弹出确认提示框
1: <script> <BR>2: var userChoice = window.confirm(“Click OK or Cancel”); <BR>3: if (userChoice) { <BR>4: document.write(“You chose OK”); <BR>5: } else { <BR>6: document.write(“You chose Cancel”); <BR>7: } <BR>8: </script>
56 提示输入
1: <script> <BR>2: var userName = window.prompt(“Please Enter Your Name”,”Enter Your Name Here”); <BR>3: document.write(“Your Name is “ + userName); <BR>4: </script>
1: <script> <BR>2: var newWindow = window.open(“”,”newWindow”); <BR>3: newWindow.document.open(); <BR>4: newWindow.document.write(“This is a new window”); <BR>5: newWIndow.document.close(); <BR>6: </script>
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn