js常用代码
function clip(text){str=document.getElementById(text);
str.select();
str = document.selection.createRange();
clipboardData.setData('text',(str.text));
alert("复制成功,您可以粘贴(Ctrl+V)到QQ或MSN上推荐给好友。")
}
String.prototype.trim=function()
{
//用正则表达式将前后空格
//用空字符串替代。
returnthis.replace(/(^\s*)|(\s*$)/g,"");
}
-- 全选按钮
function unCheckAll(form){
if(form.chkAll.checked){
form.chkAll.checked =form.chkAll.checked&0;
}
}
function checkAll(form){
for (var i=0;i<form.elements.length;i++){
var e = form.elements;
if (e.Name != "chkAll"&&e.disabled==false)
e.checked = form.chkAll.checked;
}
}
<input type="checkbox" name="chkAll" value="checkbox" />
function newXMLHttpRequest(){
var xmlreq = false;
if (window.XMLHttpRequest){
xmlreq = new XMLHttpRequest();
}else{
if (window.ActiveXObject){
try{
xmlreq = new ActiveXObject("Msxml2.XMLHTTP");
}catch (e1){
try {
xmlreq = new ActiveXObject("Microsoft.XMLHTTP");
}catch (e2){
xmlreq = false;
}
}
}
}
return xmlreq;
}
function getReadyStateHandler(req, responseXmlHandler) {
return function () {
if (req.readyState == 4) {
if (req.status == 200) {
responseXmlHandler(req.responseXML);
} else {
alert("HTTP error " + req.status + ": " + req.statusText);
}
}
};
}
String.prototype.trim = function(){
//用正则表达式将前后空格
//用空字符串替代。
return this.replace(/(^\s*)|(\s*$)/g, "");
};
function ajax(msgid){
req = newXMLHttpRequest();
var url="/personmanage/attention/zzy/myAttentionAction.do";
var paramString="m=update&msgid="+escape(msgid);
paramString=encodeURI(paramString);
//paramString=encodeURI(paramString); //有中文就要转两次
req.open("post", url, true);
req.setRequestHeader("Content-type","application/x-www-form-urlencoded");
req.send(paramString);
req.onreadystatechange = callBack;
}
/**
* 发送广播完毕
*/
function callBack() {
//Ext.MessageBox.buttonText.yes ='确定';
//Ext.MessageBox.buttonText.no ='取消';
if (req.readyState == 4){
if (req.status == 200){
var res=req.responseText;
if(res=="fail"){
Ext.MessageBox.alert('提示','您还未登录,请先登录。');
} else if(res=="true") {
Ext.MessageBox.alert('提示','更新成功!');
} else{
Ext.MessageBox.alert('提示', '处理失败,请稍后再试,或者联系运营部门......');
}
} else
Ext.MessageBox.alert('提示', '处理失败,请稍后再试,或者联系运营部门......');
}
window.location.reload();
}
页:
[1]