威尼斯人线上娱乐

Ajax小应用函数,JavaScript检查复选框选中的值个数及值

3 5月 , 2019  

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

// 关闭窗口事件
function closeWindow(){
if(event.clientX>document.body.clientWidth) {
event.returnValue = “您明确退出系统啊?”;
} else {
return;
}
}
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); 
        } 

<html> 
<head> 
<meta http-equiv=”Content-Type” content=”text/html;
charset=gb2312″> 
<title>JavaScript检查复选框选中的值个数及值</title> 
</head> 
 
<body> 
    <script language=”javascript”> 
        var i = 0; 
        for (;i<20;i++) { 
            document.write(‘<input type=”checkbox” name=”ck”
value=”‘+i+'” /><br />’); 
        } 
        document.write(‘<br /><input type=”button” id=”ckall”
name=”ckall” value=”全选” onclick=”checkall();” /> <input
type=”button” name=”delall” value=”删除所选” id=”delall” />’); 
        document.write(‘<br />  <label id=”text”
style=”display:none;”></label>’); 
        // 是还是不是全选复选框函数 
        function checkall() { 
            var ckall = document.getElementById(“ckall”); //
全选开关对象 
            var ck = document.getElementsByName(“ck”); // 复选框对象 
            // 当要施行全选时 
            if (ckall.value==”全选”) { 
                var j = 0; 
                // 循环把复选框选中 
                for (;j<20;j++) { 
                    ck[j].checked = “true”; 
                } 
                ckall.value=”全不选”; 
            } else if (ckall.value==”全不选”) { 
                // 当要推行全选时 
                document.getElementById(“delall”).disabled=false;   //
去掉delall按钮的disabled 
                document.getElementById(“delall”).value=”删除所选”; //
修改elall按键的value为“删除所选” 
                document.getElementById(“text”).style.display=”none”; //
设置 text 为隐藏 
                // 循环设置全不选 
                for (j=0;j<20;j++) { 
                    ck[j].checked = null; 
                } 
                ckall.value=”全选”; 
            } 
        } 
        var delall = document.getElementById(“delall”); 
        // 点击删除按键实行下边函数 
        delall.onclick=function(){ 
            var arr = Array();  // arr为数组 
            var ck = document.getElementsByName(“ck”); 
            for (i=0;i<20;i++) { 
                if (ck[i].checked) { 
                    arr.push(ck[i].value);  //
当复选框选中元帅选中的值累加到arr这几个数组中 
Ajax小应用函数,JavaScript检查复选框选中的值个数及值。                } 
            } 
            //
判定arr数组的个数,如果为0,那么就是从未当选,弹出警告音讯 
            if (arr.length==0) { 
                alert(‘请先选中多少!’);    
            } else if (arr.length>0){ 
                // 下边是实践删除动作 
                delall.disabled=true; // 设置delall按键为不可点 
                delall.value=”正在删除…”; //
设置delall开关的value为“正在删除…” 
                var text = document.getElementById(“text”); 
                text.style.display=”block”;   // 显示 text 
                text.style.fontSize = ‘1贰px’; // 设置字体大小 
                var t = “删除数据为:”;         // t
为text要展现的内容 
                for (j=0;j<arr.length;j++) { 
                    t += arr[j]+” “; 
                }  www.2cto.com
                text.innerHTML = t; 
            } 
        } 
    </script> 
     
</body> 
</html> 
 

入选拔消:
原生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);
  }
}

摘自 Lee.的专栏

获得是不是选中:
原生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;
}
}

 

head meta http-equiv=Content-Type
content=text/html; charset=gb231二titleJavaScript检查复选框选中的值个数及值/title /head body script
language=javascript var i =…

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

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

//张开四个新窗口

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.PRADOtrim()+ “—–” ); //去左边空格

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

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


相关文章

发表评论

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

网站地图xml地图