Ajax小应用函数

By admin in 4858美高梅 on 2019年4月15日

创建:<input type=”checkbox” id=”ck”>  

// 关闭窗口事件
function closeWindow(){
if(event.clientX>document.body.clientWidth) {
event.returnValue = “您分明退出系统吧?”;
} else {
return;
}
}
Ajax小应用函数。window.onunload = function(){
if(event.clientX>document.body.clientWidth) {
removeChat();
form1.action = “login.do?action=logout”;
form1.submit();
} else {
return;
}
};

[javascript]
function Ajax(data) 
{  
  createXMLHttpRequest(); 
  if(data==document.getElementById(“username”)) 
  { 
   
xmlhttp.open(“GET”,”user_ck.php?username=”+data.value,true);        
    document.getElementById(‘username_notice’).innerHTML =
process_request;//呈现状态  
  } 
  else if(data==document.getElementById(“veruserid”)) 
  { 
   
xmlhttp.open(“GET”,”user_ck.php?veruserid=”+data.value,true);        
    document.getElementById(“veruserid_notice”).innerHTML =
process_request;//展现状态  
  } 
   else if (data==document.getElementById(“verify”)) 
  { 
    xmlhttp.open(“POST”,”veruser_check.php”,true); 
    xmlhttp.setRequestHeader(‘Content-Type’,
‘application/x-www-form-urlencoded’); 
    document.getElementById(“verify_notice”).innerHTML =
process_request;//展现状态  
   }//”checkcode=”+checkcode.value+”&username=”+   
   xmlhttp.onreadystatechange=function() 
    {  //alert(“zhong”);  
        if (4==xmlhttp.readyState) 
        {    
            if (200==xmlhttp.status) 
            {    
                var responseText = xmlhttp.responseText; 
                responseText=
responseText.replace(/(^\s*)|(\s*$)/g,””); 
                if (responseText==”true” ) 
                {    
                    ck_user(data,”true”); 
                } 
                else 
                {   
                   ck_user(data,”false”); 
                } 
            } 
            else 
            { 
                alert(“产生错误!”); 
            } 
        } 
    } 
 if(data==document.getElementById(“veruserid”)||data==document.getElementById(“username”)) 
        {       
               xmlhttp.setRequestHeader(“If-Modified-Since”,”0″); 
               xmlhttp.send(null); 
         } 
 else if (data==document.getElementById(“verify”))       
        { 
            
xmlhttp.send(“veruserid=”+document.getElementById(“veruserid”).value+”&veruserpwd=”+document.getElementById(“verpassword”).value); 
        } 

贴起来  每一趟写麻烦

入选拔消:
原生js: document.getElementById(“ck”).checked = true[false];
Jquary: $(“#ck”).attr(“checked”, true[false]);

=========================================================================

function Ajax(data)
{
  createXMLHttpRequest();
  if(data==document.getElementById(“username”))
  {
   
xmlhttp.open(“GET”,”user_ck.php?username=”+data.value,true);      
    document.getElementById(‘username_notice’).innerHTML =
process_request;//展现状态
  }
  else if(data==document.getElementById(“veruserid”))
  {
   
xmlhttp.open(“GET”,”user_ck.php?veruserid=”+data.value,true);      
    document.getElementById(“veruserid_notice”).innerHTML =
process_request;//展现状态
  }
   else if (data==document.getElementById(“verify”))
  {
 xmlhttp.open(“POST”,”veruser_check.php”,true);
 xmlhttp.setRequestHeader(‘Content-Type’,
‘application/x-www-form-urlencoded’);
    document.getElementById(“verify_notice”).innerHTML =
process_request;//展现状态
   }//”checkcode=”+checkcode.value+”&username=”+
   xmlhttp.onreadystatechange=function()
 {  //alert(“zhong”);
  if (4==xmlhttp.readyState)
  {  
   if (200==xmlhttp.status)
   {  
    var responseText = xmlhttp.responseText;
    responseText= responseText.replace(/(^\s*)|(\s*$)/g,””);
    if (responseText==”true” )
    {  
        ck_user(data,”true”);
    }
    else
    { 
       ck_user(data,”false”);
    }
   }
   else
   {
    alert(“产生错误!”);
   }
  }
 }
 if(data==document.getElementById(“veruserid”)||data==document.getElementById(“username”))
        {     
         xmlhttp.setRequestHeader(“If-Modified-Since”,”0″);
      xmlhttp.send(null);
   }
 else if (data==document.getElementById(“verify”))  
   {
   
xmlhttp.send(“veruserid=”+document.getElementById(“veruserid”).value+”&veruserpwd=”+document.getElementById(“verpassword”).value);
  }
}

<td colspan=”4″>
                                @Html.Hidden(“hidcuidlist”)
                                <input type=”hidden” style=”border:
0px; width: 300px” id=”hidcuidnamelist” value=”” />
                            </td>
                        </tr>
                    </table>
                     <table>
                        <tr>
                            <td>
                                <input id=’CK’ type=’checkbox’
onclick=’CheckAll(this)’ />
                            </td>
                            <td>
                                全部
                            </td>
                        </tr>
                        <tr>
                            @foreach (var item in Model)
                            {    
                                     
                                <td>
                                    <input type=”checkbox” name=”cks”
id=”@item.CID” title=”@item.ChannelName” onclick=”SetCUText();”/>
                                </td>
                                <td>
                                    @item.ChannelName
                                </td>
                                        
                            }
                        </tr>
                    </table>   

赢得是不是选中:
原生js:var d = document.getElementById(“ck”).checked;
Jquary:var d = $(“#ck”).is(“:checked”);

//禁用F5键代码
function document.onkeydown(){
if(window.event.keyCode==116){
window.event.keyCode = 0;
window.event.returnValue = false;
}
}

 

js代码:

=========================================================================

] function Ajax(data) {
createXMLHttpRequest(); if(data==document.getElementById(username)) {
xmlhttp.open(GET,user_ck.php?username=+data.value,true);
document.getElemen…

<script type=”text/javascript”>
        function Validatetonum(value) {
            return value.replace(/[^\d|^\.]/g, ”); ;
        }
        //CheckAll全选
        function CheckAll(obj) {
            var items = document.getElementsByTagName(“input”);
            for (var i = 0; i < items.length; i++) {
                if (items[i].type == “checkbox” && items[i].name ==
“cks”)
                { items[i]4858美高梅 ,.checked = obj.checked; }
            }
            SetCUText();
        }
        //CheckAll全选
        function SetCUText() {
            var checkboxs = document.getElementsByName(“cks”);
            if (checkboxs[0] == undefined) {
                alert(“无选中数量!”); // 决断是或不是已有多少
            } else {
                var temp = 0; // 决断是或不是有入选项目
                var Keys = “”;
                var names = “”;
                for (var i = 0; i < checkboxs.length; i++) {
                    if (checkboxs[i].checked == true) {
                        temp++;
                        var str = checkboxs[i].id;
                        var strnames = checkboxs[i].title;
                        Keys += str + “,”;
                        names += strnames + “,”;
                    }
                }
                document.getElementById(“hidcuidlist”).value = Keys;
                document.getElementById(“hidcuidnamelist”).value =
names;
            }
        }
    </script>

//展开三个新窗口

window.open(“www.baidu.com”,”百度首页”,”height=450,width=800,status=yes,toolbar=no,menubar=no,location=no”);

=========================================================================

// 父页面获取iframe子页面包车型地铁要素

window.frames[‘mainFrame’].document.getElementById(“noticeDiv”)

=========================================================================

//决断空字符串
String.prototype.isEmpty = function(){return /^/s*$/.test(this);}

=========================================================================

// 页面跳转

window.location=”www.baidu.com”;

window.location.href = “www.baidu.com”;

=========================================================================

// uncheckAll全体撤废复选框
function uncheckAll(form,checkFlag){
var formVar = document.getElementById(form);
var x = document.getElementsByTagName(“INPUT”);
var checkAllFlag = true;
if(!checkFlag){
formVar.chkAll.checked = false;
}
else{
for(k=0;k
if(x[k].value!=”chkAll”&&x[k].type==”checkbox”&&x[k].checked==false)
checkAllFlag = false;
}
formVar.chkAll.checked = checkAllFlag;
}
}
// 全选复选框
function CheckAll(form){
var formVar = document.getElementById(form);
var x = document.getElementsByTagName(“INPUT”);
for(k=0;k
if(x[k].type==”checkbox”){
x[k].checked=formVar.chkAll.checked;
}
}
}

=========================================================================

/*赢得系统当下光阴*/
var today = new Date();
var month = today.getMonth() + 1;
var now = today.getFullYear() + “-” + month + “-” + today.getDate() + ”
00:00:00″;

=========================================================================

// 初始时间不可能超越甘休时间,无法小于当前系统时间
function validBeginAndEnd(wrongTime){
var beginTime=obj(“beginTime”).value;
var endTime=obj(“endTime”).value;
beginTime = beginTime.replace(//-/g,”//”);
endTime = endTime.replace(//-/g,”//”);
now = now.replace(//-/g,”//”);

if(new Date(beginTime) < new Date(now)){
alert(“起始时间无法小于当前系统时间啊!”);
wrongTime.value=””;
return false;
}
if(beginTime!=”” && endTime!=””){
if ((new Date(beginTime) > new Date(endTime))){
alert(“开头时间无法超过甘休时间啊!”);
wrongTime.value=””;
return false;
}
}
}

=========================================================================

// 转到修改分界面
function toModifyAuth(form) {
var formVar = document.getElementById(form);
var x = document.getElementsByTagName(“INPUT”);
var i = 0;
var authId = null;
for(k=0;k
if(x[k].value!=”chkAll”&&x[k].type==”checkbox”&&x[k].checked==true){
if(x[k].editable == “F”){
var msg = “您未有权限修改” + x[k].authName + “,请联系管理员!”;
alert(msg);
return;
}
i++;
authId = x[k].value;
}
}
if(i==1){
formVar.action = “auth.do?action=toModifyAuth&authId=” + authId;
formVar.submit();
}
if(i < 1){
alert(“请勾选您要修改的记录!”);
}
if(i > 1){
alert(“只好勾选一条记下哦!”);
}
}

=========================================================================

//校验联系电话
var patrn = /^[0-9]{1,20}$/;
var linkTel = obj(“linkTel”).value;
if (patrn.exec(linkTel) == null) {
alert(“联系电话由数字组成,请输入合法的电话号码!”);
obj(“linkTel”).focus();
obj(“linkTel”).select();
return;
}

=========================================================================

// 纯数字证实

onkeyup=”this.value=this.value.replace(//D/g,”)”
onafterpaste=”this.value=this.value.replace(//D/g,”)”

=========================================================================

// 子页面调用父页面包车型客车JavaScript方法

window.parent.showContent();

=========================================================================

// 父页面获取子页面包车型大巴Form成分saveForm,并提交该Form的多寡

window.frames[‘templateFrame’].document.getElementById(“saveForm”).action=”login.jsp”;
window.frames[‘templateFrame’].document.getElementById(“saveForm”).submit();

===========================================================================

//文件上传

在线编辑模板导入

<script language=”JavaScript” src=”${ctx
}/js/formValidate.js”></script>
<script type=”text/javascript” src=”${ctx
}/js/commonUtils.js”></script>
<script type=”text/javascript”>
// 模板导入
function importTemplate(){
if (checkForm(document.all.fileForm) == true) {
var x = document.getElementsByTagName(“input”);
for(k=0;k
if(x[k].type==”file”){
var exp =
x[k].value.substring(x[k].value.lastIndexOf(“/.”)+1).toLowerCase();
if (exp != “htm” && exp != “html”) {
alert(“只可以编辑网页文件!”);
return;
}
}
}
document.all.fileForm.action=”editorTemplate.do?action=importTemplate&operate=copy”;
fileForm.submit();
}
}

//文件上传
function addfile(){
var len = document.all.fileTable.rows.length;
var row = document.all.fileTable.insertRow(len);
var cell1 = row.insertCell();
if (window.file_i == undefined) {
window.file_i = 1;
}
cell1.innerHTML =”

” +

“;
}

//文件删除
function removeFile(srcObj) {
var currRowIndex = srcObj.parentNode.parentNode.rowIndex;
document.all.fileTable.deleteRow(currRowIndex);
}
</script>

上传模板

自定义模板

===============================================================================

// 纯数字证实

function isNumber(oNum)
{
if(!oNum) return false;
var strP=/^/d+(/./d+)?$/;
if(!strP.test(oNum)) return false;
try{
if(parseFloat(oNum)!=oNum) return false;
}
catch(ex)
{
return false;
}
return true;
}

==============================================================================

// 电话号码验证

function f_check_phoneOrMobile(obj)
{
var regu
=/(^([0][1-9]{2,3}[-])?/d{3,8}(-/d{1,6})?$)|(^/([0][1-9]{2,3}/)/d{3,8}(/(/d{1,6}/))?$)|(^/d{3,8}$)/;
var regu2 =/(^[1][3-5][0-9]{9}$)|(^0[1][3-5][0-9]{9}$)/;
var re = new RegExp(regu);
var re2=new RegExp(regu2);
if (re.test( obj.value )||re2.test(obj.value)) {
return true;
}
alert(“联系电话一定要为数字”);
return false;
}

==============================================================================

页面成分加载完今后触发

document.getElementById(“message”).onreadystatechange = function(){
if(this.readyState==”complete” ) {
documentOf(“message”).body.innerHTML=date[index-1].CONTENT;
}
}

==============================================================================

// 在弹出的小窗口页面操作父窗体的因素linknam

window.opener.document.getElementById(“linknam”).value = staffName;

==============================================================================

frames[“message”].document.designMode = “On”;

obj(“content”).value = frames[“message”].document.body.innerHTML;

==============================================================================

JS去空格处理:

String.prototype.Trim = function(){ return this .replace(/^/s+|/s+$/g,
“” );}

String.prototype.Ltrim = function(){return this .replace(/^/s+/g, “” );}

String.prototype.Rtrim = function(){return this .replace(//s+$/g, “” );}

var str=” helloworld ” ;

alert(“—-” +str.Ltrim()+ “—–” ); //去左边空格

alert(“—-” +str.CR-Vtrim()+ “—–” ); //去右侧空格

alert(“—-” +str.Trim()+ “—–” ); //两边空格都去空格

关闭窗口事件 function closeWindow(){
if(event.clientX>document.body.clientWidth) { event.returnValue =
“您分明退出系统吧?”; } else { return; } } window.onunload…

发表评论

电子邮件地址不会被公开。 必填项已用*标注

网站地图xml地图
Copyright @ 2010-2019 美高梅手机版4858 版权所有