JS中的location.host可以返回当前网址的主机名<!DOCTYPE html><html><body><script>document.write(location.host);</script></body></html>……继续阅读 » 水墨上仙 5年前 (2021-03-20) 2503浏览 1583个赞
下面的JS代码通过点击按钮控制浏览器显示上两次访问过的历史页面<!DOCTYPE html><html><head><script>function goBack() { window.history.go(-2) }</script></head><……继续阅读 » 水墨上仙 5年前 (2021-03-20) 2292浏览 1961个赞
下面的JS代码可以通过点击按钮转向下一页,当然必须用户曾经返回过上一页才能 进行此操作,否则无效。<!DOCTYPE html><html><head><script>function goForward() { window.history.forward() }</scrip……继续阅读 » 水墨上仙 5年前 (2021-03-20) 1466浏览 977个赞
点击按钮返回上一页,主要通过history.back方法实现<!DOCTYPE html><html><head><script>function goBack() { window.history.back() }</script></head><b……继续阅读 » 水墨上仙 5年前 (2021-03-20) 1593浏览 311个赞
JS中有一个history对象用于存储访问过的历史URL列表,下面的JS代码输出history中存储的历史url的数量<!DOCTYPE html><html><body><script>document.write("Number of URLs in history list: &q……继续阅读 » 水墨上仙 5年前 (2021-03-20) 3219浏览 1360个赞
下面的JS代码通过screen对象获得用户屏幕的相关信息,包括分辨率、颜色数等等<!DOCTYPE html><html><body><h3>Your Screen:</h3><script>document.write("Total width/height……继续阅读 » 水墨上仙 5年前 (2021-03-20) 3112浏览 224个赞
下面的JS代码列举了可以从客户端浏览器获得的相关信息,包括浏览器类型、浏览器名称、版本号、是否允许cookie、userAgent、系统语言等等<!DOCTYPE html><html><body><div id="example"></div><script……继续阅读 » 水墨上仙 5年前 (2021-03-20) 2423浏览 1137个赞
下面的JS代码点击开始按钮后开始计时,点击停止按钮后停止计时<!DOCTYPE html><html><head><script>var c=0;var t;var timer_is_on=0;function timedCount(){document.getElementById(&……继续阅读 » 水墨上仙 5年前 (2021-03-20) 2560浏览 385个赞
通过JavaScript重置表单(reset)的方法,下面的代码可以对表单内的输入数据进行重置<!DOCTYPE html><html><head><script>function formReset(){document.getElementById("frm1").res……继续阅读 » 水墨上仙 5年前 (2021-03-20) 1600浏览 2178个赞
JavaScript获得表单的target属性<!DOCTYPE html><html><body><form id="frm1" action="form_action.asp" target="_blank">First name: ……继续阅读 » 水墨上仙 5年前 (2021-03-20) 1808浏览 1238个赞
下面的代码通过表单的name属性获得表单名称<!DOCTYPE html><html><body><form id="frm1" name="form1">First name: <input type="text" name=&q……继续阅读 » 水墨上仙 5年前 (2021-03-20) 3241浏览 1521个赞
JavaScript获取网页表单的提交方式是get还是post,获取提交方式可以通过表单的method属性获得<!DOCTYPE html><html><body><form id="frm1" action="form_action.asp" method=&qu……继续阅读 » 水墨上仙 5年前 (2021-03-20) 2030浏览 2223个赞
JavaScript显示表单内元素的数量,不包含表单本身<!DOCTYPE html><html><body><form id="frm1" action="form_action.asp">First name: <input type="……继续阅读 » 水墨上仙 5年前 (2021-03-20) 1624浏览 671个赞
JavaScript返回表单的enctype属性<!DOCTYPE html><html><body><form id="frm1" enctype="text/plain">First name: <input type="text&quo……继续阅读 » 水墨上仙 5年前 (2021-03-20) 1731浏览 857个赞
JavaScript获取网页表单的action属性,即要提交到的url地址,有时候需要提交到当前页面,则可能会设置action为空,下面代码提取到的action属性也为空。<!DOCTYPE html><html><body><form id="frm1" action="s……继续阅读 » 水墨上仙 5年前 (2021-03-20) 2742浏览 442个赞
JavaScript获取网页支表单持的字符集,通过表单的acceptCharset方法获得<!DOCTYPE html><html><body><form id="frm1" accept-charset="ISO-8859-1">First name: &……继续阅读 » 水墨上仙 5年前 (2021-03-20) 2383浏览 2447个赞
下面的JS代码可以遍历指定表单中的所有元素,并输出元素的值<!DOCTYPE html><html><body><form id="frm1" action="form_action.aspx"> First name: <input type=&q……继续阅读 » 水墨上仙 5年前 (2021-03-20) 2369浏览 539个赞
知道按钮的id向获取按钮放在哪一个表单内,可以通过下面的JS代码获取<!DOCTYPE html><html><body><h1>www.75271.com</h1><form id="form1"><button id="button1……继续阅读 » 水墨上仙 5年前 (2021-03-20) 2051浏览 1572个赞
按钮有一个value属性,我们可以通过按钮的value属性获得按钮上显示的文本<!DOCTYPE html><html><body><input type="button" id="button1" value="Click Me!">……继续阅读 » 水墨上仙 5年前 (2021-03-20) 3180浏览 1838个赞
下面的JS代码通过按钮对象的disabled属性控制按钮是否可用<!DOCTYPE html><html><body><form>Buttons:<input type="button" id="firstbtn" value="OK&qu……继续阅读 » 水墨上仙 5年前 (2021-03-20) 2916浏览 1765个赞
JavaScript获取网上指定id的按钮的名字(name),按钮包含了name属性,可以直接获取<!DOCTYPE html><html><body><button id="button1" name="button1">Click Me!</butt……继续阅读 » 水墨上仙 5年前 (2021-03-20) 3017浏览 1327个赞
如果网页中定义了base,我们可以通过js代码获得base url地址<!DOCTYPE html><html><head><base id="htmldom" href="http://www.75271.com/jsref/"></head>……继续阅读 » 水墨上仙 5年前 (2021-03-20) 2827浏览 2396个赞
JS中的document.title可以获取当前网页的标题<!DOCTYPE html><html><head><title>75271.com</title></head><body>current document's title is: &……继续阅读 » 水墨上仙 5年前 (2021-03-20) 2179浏览 548个赞
下面的JS代码通过document.referrer获得来源页面地址<!DOCTYPE html><html><body>The referrer of this document is:<script>document.write(document.referrer);</script……继续阅读 » 水墨上仙 5年前 (2021-03-20) 3004浏览 248个赞
下面的JS代码输出当前网页最后修改时间,用到了document.lastModified属性<!DOCTYPE html><html><body>This document was last modified on:<script>document.write(document.lastModi……继续阅读 » 水墨上仙 5年前 (2021-03-20) 2685浏览 687个赞
JavaScript获得当前日期是星期几,主要通过getDay函数获得当前日期是一个星期的第几天<!DOCTYPE html><html><body><p id="demo">Click the button to display todays day of the week.&……继续阅读 » 水墨上仙 5年前 (2021-03-20) 1511浏览 2151个赞
JavaScript通过replace函数替换字符串,下面的代码将Visit Microsoft中的MicroSoft替换成75271.com<!DOCTYPE html><html><body><p>Click the button to replace "Microsoft"……继续阅读 » 水墨上仙 5年前 (2021-03-20) 1904浏览 1586个赞
JavaScript通过indexOf获得子字符串在字符串中的位置<!DOCTYPE html><html><body><p id="demo">Click the button to locate where in the string a specifed value occ……继续阅读 » 水墨上仙 5年前 (2021-03-20) 2314浏览 746个赞
字符串对象有一个公用的属性length用于获得字符串的长度<!DOCTYPE html><html><body><script>var txt = "Hello World!";document.write(txt.length);</script>&l……继续阅读 » 水墨上仙 5年前 (2021-03-20) 2694浏览 2228个赞
下面的代码通过函数的方式定义了一个对象person,并通过new方法对其进行实例化<!DOCTYPE html><html><body><script>function person(firstname,lastname,age,eyecolor){this.firstname=firstna……继续阅读 » 水墨上仙 5年前 (2021-03-20) 1501浏览 2467个赞
JavaScript中可以直接通过类似python字典的方式定义对象,下面的代码你一看就能明白怎么回事,不用多说。<!DOCTYPE html><html><body><script>person={firstname:"John",lastname:"Doe&quo……继续阅读 » 水墨上仙 5年前 (2021-03-20) 1587浏览 2978个赞
JavaScript通过setTimeout显示一个简单的电子时钟,这段代码主要演示了时间函数和setTimeout定时执行函数的用法<!DOCTYPE html><html><head><script>function startTime(){var today=new Date();var……继续阅读 » 水墨上仙 5年前 (2021-03-20) 2971浏览 1516个赞
下面的代码执行后点击按钮会延迟3秒钟弹出一个警告框,主要演示了setTimeout的使用方法<!DOCTYPE html><html><body><p>75271.com Click the button to wait 3 seconds, then alert "Hello"……继续阅读 » 水墨上仙 5年前 (2021-03-20) 2682浏览 456个赞
点击按钮后每隔一秒计数器增加1,通过setTimeout实现<!DOCTYPE html><html><head><script>var c=0;var t;var timer_is_on=0;function timedCount(){document.getElementById(&……继续阅读 » 水墨上仙 5年前 (2021-03-20) 3032浏览 746个赞
下面的代码通过try…catch语句捕捉错误后弹出confirm对话框,如果用户点击cancel按钮则跳转至首页<!DOCTYPE html><html><head><script>var txt="";function message(){try { ……继续阅读 » 水墨上仙 5年前 (2021-03-20) 2387浏览 1220个赞
我们可以通过设定按钮的onclick属性来给按钮绑定onclick事件<!DOCTYPE html><html><head><script>function displayDate(){document.getElementById("demo").innerHTML=Dat……继续阅读 » 水墨上仙 5年前 (2021-03-20) 2976浏览 2344个赞
JavaScript中通过for…in语句遍历对象,JS中我们可以通过for..in语句输出对象的每一个元素和元素值<!DOCTYPE html><html><body><p>75271.com Click the button to loop through the properties……继续阅读 » 水墨上仙 5年前 (2021-03-20) 3333浏览 2213个赞
和C语言一样,JavaScript中可以通过break语句终止循环的继续执行<!DOCTYPE html><html><body><p>75271.com Click the button to do a loop with a break.</p><button onclick……继续阅读 » 水墨上仙 5年前 (2021-03-20) 2675浏览 1088个赞
下面的代码演示了JavaScript中do…while循环语句的使用方法<!DOCTYPE html><html><body><p>Click the button to loop through a block of as long as <em>i</em> ……继续阅读 » 水墨上仙 5年前 (2021-03-20) 2951浏览 1610个赞
下面的JS代码监听文本框的onkeydown和onkeyup事件,分别在键盘按下和弹起时触发,并定义setStatus函数响应键盘事件<script type="text/javascript">function setStatus(name,evt) {evt = (evt) ? evt : ((event) ? ……继续阅读 » 水墨上仙 5年前 (2021-03-20) 2262浏览 706个赞
下面的JS代码通过window.open打开链接,通过this.href获取当前超级链接。<a href='http://www.75271.com'onclick='window.open(this.href,"Pennies","resizable=yes,status=yes,……继续阅读 » 水墨上仙 5年前 (2021-03-20) 1748浏览 1678个赞
下面的JS代码可以统计表单中有多少个checkbox被选中,在问卷调查中经常会用到<form name="form3" action="#"><div>Who are your favorite browncoats? Please select all that apply to ……继续阅读 » 水墨上仙 5年前 (2021-03-20) 3187浏览 1493个赞
JavaScript向OL列表内动态添加LI元素的方法,下面JS代码每次点击按钮都会想OL列表中动态添加一个LI<script type="text/javascript">function addItem() { var myitem = document.getElementById("ItemToAd……继续阅读 » 水墨上仙 5年前 (2021-03-20) 2542浏览 2532个赞
下面的JS代码当用户点击提交按钮后,通过元素的textContent或者innerHTML动态指定元素的内容<script type="text/javascript">function showCard() { var message = document.getElementById("CCN"……继续阅读 » 水墨上仙 5年前 (2021-03-20) 1448浏览 239个赞
表单提交时通过JavaScript判断哪个radio按钮被选中了<script type="text/javascript">function findButton() {var myForm = document.forms.animalForm;var i;for(i=0;i<myForm.marsup……继续阅读 » 水墨上仙 5年前 (2021-03-20) 3128浏览 1779个赞