日期:2014-05-17  浏览次数:20780 次

总结JAVASCRIPT和HTML基础
1.Confim
在html标记添加确认,加上
onclick="return confirm('您确定要删除这个数据吗?')"

在js方法里添加确认,加上
if(confirm('确定要删除选中的数据吗?'))
{
     document.listForm.submit();
}


2.可用与不可用
在html标记里添加disabled表示当前控件不可用,readonly表示当前控件只读,enabled表示当前控件可用。
在js方法里通过disabled=true表示某空间不可用。

3.浏览器回退
window.history.back();


4.限制输入框长度
在html标记里添加maxlength="500"。
//限制textArea的长度
onkeyup="return limitMaxLength(this)"
function limitMaxLength(obj){
  var mlength = obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""
  if (obj.getAttribute && obj.value.length > mlength){
    obj.value = obj.value.substring(0,mlength);
  }
}


5.设置页面不被浏览器缓存
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<meta http-equiv="Cache-Control" content="no-store"/>
<meta http-equiv="Pragma" content="no-cache"/>
<meta http-equiv="Expires" content="0"/>



6.修改样式名称
object.className="";


7.显示和隐藏
object.style.display="none";//隐藏
object.style.display="";//显示


8.刷新页面
1 history.go(0) 
2 location.reload() 
3 location=location 
4 location.assign(location) 
5 document.execCommand(‘Refresh‘) 
6 window.navigate(location) 
7 location.replace(location) 
8 document.URL=location.href.自动刷新页面的方法:
1.页面自动刷新:把如下代码加入<head>区域中<meta http-equiv="refresh" content="20">其中20指每隔20秒刷新一次页面.
2.<body onload="opener.location.reload()"> 开窗时刷新
3.<body onUnload="opener.location.reload()"> 关闭时刷新


9.使用锚
使用锚(mao)可以定位到页面的某个地方
格式:URL+#+元素的ID(最好是<a>的ID),
例子:http://www.google.com#edit。
http://www.google.com页面里有一个<a id="edit"></a>的元素

10.定时执行JS函数
setInterval("pushIDSEvent()",5000);//间隔5秒

获取浏览器语言
window.navigator.systemLanguage


document.location
document.location     这个对象包含了当前URL的信息
location.host 获取port号
location.hostname 设置或获取主机名称
location.href 设置或获取整个URL
location.port设置或获取URL的端口号
location.search     设置或获取href属性中跟在问号后面的部分

触发enter事件
方法一在组件上加
onkeydown="javascript:if(event.keyCode==13){alert(1);return false;}"

方法二写在函数里
<script language="javascript"> 
function enterkey(eventTag) 
{ 
	var event = eventTag||window.event;  
	var currentKey = event.charCode||event.keyCode;
	if (currentKey==13) 
	{ 
		// do something. 
		alert(currentKey);
		event.returnValue= false; // 取消此事件的默认操作 
	} 
} 
</script> 
<body> 
<input type="text" id="corpName" class="ins ins1" onkeydown="enterkey(event);" />
</body> 


设置网页的图标
<link rel="shortcut icon" href="http://img.s.aliimg.com/favicon.ico">
<link rel="Bookmark" href="http://img.s.aliimg.com/favicon.ico">