JavaScript的Math对象包含了一个round方法用于对数字进行四舍五入操作,下面的代码详细演示了其用法<!DOCTYPE html><html><body><p id="demo">Click the button to round the number 2.5 to ……继续阅读 » 水墨上仙 5年前 (2021-03-20) 2581浏览 1326个赞
JS数组带有一个unshift方法可以再数组前面添加若干个元素,下面是详细的代码演示<!DOCTYPE html><html><body><p id="demo">Click the button to add elements to the array.</p>……继续阅读 » 水墨上仙 5年前 (2021-03-20) 2427浏览 1689个赞
我们可以通过JS数组的splice方法在执行的位置插入新的元素,非常简单<!DOCTYPE html><html><body><p id="demo">Click the button to add elements to the array.</p><bu……继续阅读 » 水墨上仙 5年前 (2021-03-20) 2100浏览 2804个赞
JS数组的sort方法支持使用函数作为参数,下面的代码演示了JS数组如何通过sort对数字类型的数组进行倒序排序<!DOCTYPE html><html><body><p id="demo">Click the button to sort the array.</p>……继续阅读 » 水墨上仙 5年前 (2021-03-20) 1828浏览 2461个赞
JS数组的sort方法支持一个函数作为参数,下面的代码演示了JS数组如何实现数字的正序排列<!DOCTYPE html><html><body><p id="demo">Click the button to sort the array.</p><butt……继续阅读 » 水墨上仙 5年前 (2021-03-20) 1562浏览 2599个赞
JS数组带有一个sort方法可以给数组排序,非常简单<!DOCTYPE html><html><body><p id="demo">Click the button to sort the array.</p><button onclick="my……继续阅读 » 水墨上仙 5年前 (2021-03-20) 3286浏览 1017个赞
JS数组带有一个slice方法,可以获取数组的指定部分,下面的代码获取数组中的第二个和第三个元素<!DOCTYPE html><html><body><p id="demo">Click the button to extract the second and the third……继续阅读 » 水墨上仙 5年前 (2021-03-20) 3197浏览 663个赞
JS中我们可以通过pop方法移除数组的最后一个元素,可以通过shift方法移除数组的第一个元素<!DOCTYPE html><html><body><p id="demo">Click the button to remove the first element of the a……继续阅读 » 水墨上仙 5年前 (2021-03-20) 2774浏览 2705个赞
下面的代码演示了JS中如果通过数组的reverse方法将数组元素反转过来<!DOCTYPE html><html><body><p id="demo">Click the button to reverse the order of the elements in the arr……继续阅读 » 水墨上仙 5年前 (2021-03-20) 2806浏览 1186个赞
下面的代码演示了JS数组通过push方法添加一个元素到数组末尾<!DOCTYPE html><html><body><p id="demo">Click the button to add a new element to the array.</p><bu……继续阅读 » 水墨上仙 5年前 (2021-03-20) 1515浏览 415个赞
下面的代码演示了JS数组的pop方法,可以用来移除数组的最后一个元素,实际上就是把数组当成堆栈使用<!DOCTYPE html><html><body><p id="demo">Click the button to remove the last array element.&……继续阅读 » 水墨上仙 5年前 (2021-03-20) 2963浏览 2989个赞
下面的代码演示了JS中如何通过contact函数链接多个数组<!DOCTYPE html><html><body><script>var parents = ["Jani", "Tove"];var brothers = ["Stale&quo……继续阅读 » 水墨上仙 5年前 (2021-03-20) 2351浏览 610个赞
下面的JS代码输出全部的cookie键值对照<!DOCTYPE html><html><body>Cookies associated with this document: <script>document.write(document.cookie);</script>&l……继续阅读 » 水墨上仙 5年前 (2021-03-20) 1380浏览 614个赞
下面的JS代码通过document.links获得网页中的所有超级链接数组,然后获得第一个链接的ID属性<!DOCTYPE html><html><body><h1>75271.com</h1><img src ="planets.gif" width=&quo……继续阅读 » 水墨上仙 5年前 (2021-03-20) 1988浏览 2361个赞
下面的JS代码通过document.links获取网页中的所有超级链接,从而获得超级链接的数量<!DOCTYPE html><html><body><img src ="planets.gif" width="145" height="126" ……继续阅读 » 水墨上仙 5年前 (2021-03-20) 2247浏览 161个赞
下面的代码通过document.images获取网页中的所有图片,然后获取第一个图片的id属性<!DOCTYPE html><html><body><img id="klematis lilac" border="0" src="klematis.jpg&……继续阅读 » 水墨上仙 5年前 (2021-03-20) 2783浏览 2180个赞
下面的JS代码通过document.forms数组获取网页中的表单,并返回第一个表单的name属性,即名字<!DOCTYPE html><html><body><h1>75271.com</h1><form name="Form1"></form&g……继续阅读 » 水墨上仙 5年前 (2021-03-20) 3055浏览 2731个赞
下面的JS代码通过document.images数组获取网页中图片数量<!DOCTYPE html><html><body><h1><a href="http://www.75271.com">脚本分享网</a></h1><img bor……继续阅读 » 水墨上仙 5年前 (2021-03-20) 2084浏览 522个赞
下面的JS代码通过document.forms数组获得网页中表单(form)的数量<!DOCTYPE html><html><body><h1>75271.com</h1><form name="Form1"></form><form ……继续阅读 » 水墨上仙 5年前 (2021-03-20) 2956浏览 2914个赞
下面的JS代码通过document.archors数组获取第一个archor的innerHTML<!DOCTYPE html><html><body><a name="html">75271.com</a><br><a name="css……继续阅读 » 水墨上仙 5年前 (2021-03-20) 3157浏览 972个赞
JavaScript返回网页中锚定的数目,下面的JS代码获取页面中的anchor数量<!DOCTYPE html><html><body><a name="html">HTML Tutorial</a><br><a name="css&……继续阅读 » 水墨上仙 5年前 (2021-03-20) 1525浏览 1380个赞
下面的JS代码写在iframe里面,点击按钮后整个网页会转向指定的url,而不是只转iframe里的页面<!DOCTYPE html><html><head><script>function breakout(){if (window.top!=window.self) { windo……继续阅读 » 水墨上仙 5年前 (2021-03-20) 2652浏览 2177个赞
下面的JS代码可以替换当前页面为指定的URL<!DOCTYPE html><html><head><script>function replaceDoc() { window.location.replace("http://www.75271.com") }<……继续阅读 » 水墨上仙 5年前 (2021-03-20) 1603浏览 2141个赞
下面的JS代码可以重新加载当前页面<!DOCTYPE html><html><head><script>function reloadPage() { location.reload() }</script></head><body><……继续阅读 » 水墨上仙 5年前 (2021-03-20) 2312浏览 2718个赞
下面的JS代码点击按钮后可以控制网页转向指定的url<!DOCTYPE html><html><head><script>function newDoc() { window.location.assign("http://www.75271.com") }<……继续阅读 » 水墨上仙 5年前 (2021-03-20) 1574浏览 1580个赞
下面的JS代码返回当前浏览网页的相对路径,就是不要域名部分的路径,如:/codes/share<!DOCTYPE html><html><body><script>document.write(location.pathname);</script></body>……继续阅读 » 水墨上仙 5年前 (2021-03-20) 2443浏览 1414个赞
JavaScript获取当前浏览网页的完整地址,JS中我们可以通过location对象的href来获取完整url地址<!DOCTYPE html><html><body><script>document.write(location.href);</script></b……继续阅读 » 水墨上仙 5年前 (2021-03-20) 1465浏览 598个赞
JS中的location.host可以返回当前网址的主机名<!DOCTYPE html><html><body><script>document.write(location.host);</script></body></html>……继续阅读 » 水墨上仙 5年前 (2021-03-20) 1524浏览 447个赞
下面的JS代码通过点击按钮控制浏览器显示上两次访问过的历史页面<!DOCTYPE html><html><head><script>function goBack() { window.history.go(-2) }</script></head><……继续阅读 » 水墨上仙 5年前 (2021-03-20) 1500浏览 1733个赞
下面的JS代码可以通过点击按钮转向下一页,当然必须用户曾经返回过上一页才能 进行此操作,否则无效。<!DOCTYPE html><html><head><script>function goForward() { window.history.forward() }</scrip……继续阅读 » 水墨上仙 5年前 (2021-03-20) 2929浏览 361个赞
点击按钮返回上一页,主要通过history.back方法实现<!DOCTYPE html><html><head><script>function goBack() { window.history.back() }</script></head><b……继续阅读 » 水墨上仙 5年前 (2021-03-20) 3368浏览 494个赞
JS中有一个history对象用于存储访问过的历史URL列表,下面的JS代码输出history中存储的历史url的数量<!DOCTYPE html><html><body><script>document.write("Number of URLs in history list: &q……继续阅读 » 水墨上仙 5年前 (2021-03-20) 2834浏览 905个赞
下面的JS代码通过screen对象获得用户屏幕的相关信息,包括分辨率、颜色数等等<!DOCTYPE html><html><body><h3>Your Screen:</h3><script>document.write("Total width/height……继续阅读 » 水墨上仙 5年前 (2021-03-20) 1480浏览 2979个赞
下面的JS代码列举了可以从客户端浏览器获得的相关信息,包括浏览器类型、浏览器名称、版本号、是否允许cookie、userAgent、系统语言等等<!DOCTYPE html><html><body><div id="example"></div><script……继续阅读 » 水墨上仙 5年前 (2021-03-20) 2820浏览 1504个赞
下面的JS代码点击开始按钮后开始计时,点击停止按钮后停止计时<!DOCTYPE html><html><head><script>var c=0;var t;var timer_is_on=0;function timedCount(){document.getElementById(&……继续阅读 » 水墨上仙 5年前 (2021-03-20) 1537浏览 643个赞
通过JavaScript重置表单(reset)的方法,下面的代码可以对表单内的输入数据进行重置<!DOCTYPE html><html><head><script>function formReset(){document.getElementById("frm1").res……继续阅读 » 水墨上仙 5年前 (2021-03-20) 3134浏览 939个赞
JavaScript获得表单的target属性<!DOCTYPE html><html><body><form id="frm1" action="form_action.asp" target="_blank">First name: ……继续阅读 » 水墨上仙 5年前 (2021-03-20) 3117浏览 2650个赞
下面的代码通过表单的name属性获得表单名称<!DOCTYPE html><html><body><form id="frm1" name="form1">First name: <input type="text" name=&q……继续阅读 » 水墨上仙 5年前 (2021-03-20) 1662浏览 227个赞
JavaScript获取网页表单的提交方式是get还是post,获取提交方式可以通过表单的method属性获得<!DOCTYPE html><html><body><form id="frm1" action="form_action.asp" method=&qu……继续阅读 » 水墨上仙 5年前 (2021-03-20) 2571浏览 2968个赞
JavaScript显示表单内元素的数量,不包含表单本身<!DOCTYPE html><html><body><form id="frm1" action="form_action.asp">First name: <input type="……继续阅读 » 水墨上仙 5年前 (2021-03-20) 2691浏览 1312个赞
JavaScript返回表单的enctype属性<!DOCTYPE html><html><body><form id="frm1" enctype="text/plain">First name: <input type="text&quo……继续阅读 » 水墨上仙 5年前 (2021-03-20) 2153浏览 2143个赞
JavaScript获取网页表单的action属性,即要提交到的url地址,有时候需要提交到当前页面,则可能会设置action为空,下面代码提取到的action属性也为空。<!DOCTYPE html><html><body><form id="frm1" action="s……继续阅读 » 水墨上仙 5年前 (2021-03-20) 3357浏览 2547个赞
JavaScript获取网页支表单持的字符集,通过表单的acceptCharset方法获得<!DOCTYPE html><html><body><form id="frm1" accept-charset="ISO-8859-1">First name: &……继续阅读 » 水墨上仙 5年前 (2021-03-20) 1802浏览 778个赞
下面的JS代码可以遍历指定表单中的所有元素,并输出元素的值<!DOCTYPE html><html><body><form id="frm1" action="form_action.aspx"> First name: <input type=&q……继续阅读 » 水墨上仙 5年前 (2021-03-20) 2530浏览 2721个赞
知道按钮的id向获取按钮放在哪一个表单内,可以通过下面的JS代码获取<!DOCTYPE html><html><body><h1>www.75271.com</h1><form id="form1"><button id="button1……继续阅读 » 水墨上仙 5年前 (2021-03-20) 1780浏览 157个赞