Tag Archives: js

Ajax常见问题有哪些?

今天我来说一下经常在使用js时遇到的三个问题,网友们也可以给我留言写上更多的常见问题。 一,js脚本缓存问题 答:这个问题是大家遇到最常见问题之一,因为修改了js内容调试的时候 并不能显示新写代码的结果,是因为js为了加速页面执行,当前页面会使用缓存保持 当前调用的相同连接。为了开发时调试方便可以在连接地址的后面增加一个随机函数。 如原地址:header.js 增加随机后 header.js?12581 二,本地调试js脚本不起作用 答:因为使用ajax传递参数的时候需要head支持,所以我们只有在站点下才可以 成功,比如我们放在Apache下面或者IIS下面进行调试。 三,调试代码查找错误困难 答:这是js调试存在已久的问题,简单点我们可以使用ie默认提示的错误框,还有就 是我们可以使用DW CS4提供的纠正错误,或者通过专业的插件如:firbug 等

Jquery tab 选项卡 无刷新切换

这个jquery主要功能是:当点击导航按钮时无刷新切换你想要显示的内容,并且还带有淡入效果 下面介绍一下js代码:   $(document).ready(function() {   //默认情况下 $(".tab_content").hide(); //隐藏所有内容 $("ul.tabs li:first").addClass("active").show(); //显示第一个标签 $(".tab_content:first").show(); //显示第一个标签的内容   //点击情况下 $("ul.tabs li").click(function() { $("ul.tabs li").removeClass("active"); //删除任何命名为"active"的class $(this).addClass("active"); //添加名为"active"的class的标签 $(".tab_content").hide(); //隐藏所有标签的内容 var activeTab = $(this).find("a").attr("href"); //查找href属性值来确定当前标签+内容 $(activeTab).fadeIn(); //显示内容淡入效果 return false; }); }); 演示代码如:无刷新切换

js 回车键搜索

下面这个表示页面中只有一个回车键按钮的时候: function document.onkeydown(){ if(event.keyCode==13){ document.getElementById("search_b").click(); return false; } } 下面这样就表示取消回车键 if (window.event.keyCode==13){ window.event.keyCode=0; } 下面这个表示页面中有两个回车键按钮的时候: function document.onkeydown(){ var activeObj = document.activeElement; if(event.keyCode==13){ if (activeObj.name=="USER_PASS" || activeObj.name=="USER_ID") { document.getElementById("loginln").click(); return false; } else { document.getElementById("search_b").click(); return false; } } } 下面是html代码: <input type="image" name="search_b" id="search_b" src="search.gif" border="0" onclick="javascript:document.submit();" >

页面中按钮刷新的几种方法

<input onclick="history.go(0)" type="button" value="刷新" />   <input onclick="location.reload()" type="button" value="刷新" />   <input onclick="location=location" type="button" value="刷新" />   <input onclick="location.assign(location)" type="button" value="刷新" />   <input onclick="document.execCommand(‘Refresh’)" type="button" value="刷新" />   <input onclick="window.navigate(location)" type="button" value="刷新" />   <input onclick="location.replace(location)" type="button" value="刷新" />   <input onclick="window.open(‘自身的文件’,'_self’)" type="button" value="刷新" />   <input onclick="document.all.WebBrowser.ExecWB(22,1)" type="button" value="刷新" />

JS创建图片对象的两种方法

第一种方法: var img = new Image(); img.src ="http://www.huaidong.net/" 第二种方法: var img_2 =document.createElement("img"); img_2.src = "http://www.huaidong.net/";

js 图片预加载

图片预加载

js 多长时间运行一次

onload open

js 各种文字滚动代码

文字向右滚动

js 遮挡层和半透明背景

<html> <head> <title></title> <style> #sorry { background:#ccc; width:410px; height:410px; left:50%; top:50%; margin-top:-200px; margin-left:-200px; position:absolute; z-index:100; } #sorry_close { text-align:center; } #sorry_img { border:5px solid #ccc; } #ok { z-index:100; } #div_body { filter: Alpha(Opacity=50); opacity: 0.50; z-index:50; } </style> </style> <script type="text/javascript"> function spreen() { var sorry = document.getElementById(’sorry’); var div_body = document.getElementById(’div_body’); sorry.style.position = [...]

js检查页面上有无重复id

注:请考虑效率问题,因为页面上可能有上千id。 window.onload = function(){ var t = new Date(), hsh = {}, arr = [], d; var o = document.getElementsByTagName("*"); var m = o.length; while(–m) !(d=o[m].id) || !hsh[d] && (hsh[d]="*") || (arr[arr.length]=d); alert("用时:" + [new Date()-t] + "毫秒"); alert("重复项为:" + arr.join("")) }     <body> var html = []; for(var i = 0; i < [...]