JS
/* * Javascript base64encode() base64加密函数 用于生成字符串对应的base64加密字符串 * @param string input 原始字符串 * @return string 加密后的base64字符串 */ function base64Encode(input) { var rv; rv = encodeURIComponent(input); rv = unescape(rv); rv = window.btoa(rv); return rv; } /* * Javascript base64Decode() base64解密函数 用于解密base64加密的字符串 * @param string input base64加密字符串 * @return string 解密后的字符串 */ function base64Decode(input) { rv = window.atob(input); rv = escape(rv); rv = decodeURIComponent(rv); return rv; } //获取url中的参数 function getUrlParam(name) { var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象 var r = window.location.search.substr(1).match(reg); //匹配目标参数 if (r != null) return unescape(r[2]); return null; //返回参数值 } //使用POST方式打开界面 function doOpenPostWin(URL, PARAMS) { var temp_form = document.createElement("form"); temp_form.action = URL; temp_form.target = "_blank"; temp_form.method = "post"; temp_form.style.display = "none"; for (var x in PARAMS) { var opt = document.createElement("textarea"); opt.name = x; opt.value = PARAMS[x]; temp_form.appendChild(opt); } document.body.appendChild(temp_form); temp_form.submit(); } //用post打开新窗口 var url = '?a=lu&m=input&d=flow&num=drfinpay&crm_ordern_new_mid=' + ordern_new_mid + '&sericnum=' + sericnum + '&callback=opegs1621839221750_8416&applicationtype=fksq'; sessionStorage.setItem('drfinpayzb1', drfinpayzb1arr) doOpenPostWin(url, {drfinpayzb1: drfinpayzb1arr});
jquery判断字符串中是否包含特定字符的方法总结
var Cts = "bblText"; if(Cts.indexOf("Text") >= 0 ) { alert('Cts中包含Text字符串'); } //索引数组定义 var drfinpayzb1arr = []; for (var i = 0; i < lineNum; i++) { var arr = looking_list_arr.slice(i * size, (size * (i + 1))); var uniqueId = arr.eq(1).text(); var nickname = arr.eq(3).text(); var temp = new Object(); temp.sdt = date; temp.ordern_new_mid = ordern_new_mid; temp.uniqueId = uniqueId; temp.nickname = nickname; drfinpayzb1arr.push(temp); } //数组转json base64Encode加密 drfinpayzb1arr = JSON.stringify(drfinpayzb1arr); drfinpayzb1arr = base64Encode(drfinpayzb1arr); //打开新窗口 var url = '?a=lu&m=input&d=flow&num=drfinpay&crm_ordern_new_mid=' + ordern_new_mid + '&sericnum=' + sericnum + '&callback=opegs1621839221750_8416&drfinpayzb1=' + drfinpayzb1arr; window.open(url);
获取当前日期时间
var myDate = new Date;
var year = myDate.getFullYear(); //获取当前年
var mon = myDate.getMonth() + 1; //获取当前月
var date = myDate.getDate(); //获取当前日
// var h = myDate.getHours();//获取当前小时数(0-23)
// var m = myDate.getMinutes();//获取当前分钟数(0-59)
// var s = myDate.getSeconds();//获取当前秒
var week = myDate.getDay();
var weeks = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"];
console.log(year, mon, date, weeks[week])
$("#time").html(year + "年" + mon + "月" + date + "日" + weeks[week]);
//全选反选 $("#selection_all").click(function(){ var check=$('#selection_all').is(':checked'); if(check){ $("input[name='isdrfinpayzb1']").attr("checked",true); } else{ $("input[name='isdrfinpayzb1']").attr("checked",false); } });
$.ajax({ url: url, success: function (ret) { var data = JSON.parse(ret) if (data.nowcourseid == 551) { $("#drfksq").show(); if (data.ordernnewlist) { $('.ys0 table tr:first').prepend('<td style="padding:3px;border:1px #cccccc solid;border-top:none" bgcolor="#eeeeee" align="center" data-column="uniqueId"><b>全选<input style="float: right;margin-top: 15px;margin-right: 25px;" type="checkbox" name="selection_all"></b></td>'); $('.ys0 table tr:gt(0)').prepend('<td style="padding:3px;border:1px #cccccc solid" align="center"><input type="checkbox" name="isdrfinpayzb1" class="isdrfinpayzb1"> </td>'); $.each(data.ordernnewlist, function (index, value) { if (value.isdrfinpayzb1 == 1) { var lent = index + 1; $(".ys0 table tr:eq(" + lent + ") td:eq(0) input").attr("style", "cursor:not-allowed"); $(".ys0 table tr:eq(" + lent + ") td:eq(0) input").attr("disabled", "disabled"); } }); } } } });
//获取url中的参数 function getUrlParam(name) { var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象 var r = window.location.search.substr(1).match(reg); //匹配目标参数 if (r != null) return unescape(r[2]); return null; //返回参数值 } //删除空格字符 companyname = companyname.replace(/^\s*|\s*$/g,""); //删除指定├字符 companyname = companyname.replace("├", "");
select点击事件
$("select[name='companyid']").change(function() { // 获取select中选中option的文本值 var text =$(this).find("option:selected").text() // 获取select中选中option的value值 var opval=this.options[this.selectedIndex].value; console.log(opval+'-----'+text) })
加法
var c = parseInt(a) + parseInt(b)
jq json数据解密和遍历
drfinpayzb1 = eval(drfinpayzb1); for(var key in drfinpayzb1){ console.log(key);//从0开始 console.log(drfinpayzb1[key].nickname); console.log(drfinpayzb1[key]); } /* * Javascript base64encode() base64加密函数 用于生成字符串对应的base64加密字符串 * 吴先成 www.51-n.com ohcc@163.com QQ:229256237 * @param string input 原始字符串 * @return string 加密后的base64字符串 */ function base64Encode(input){ var rv; rv = encodeURIComponent(input); rv = unescape(rv); rv = window.btoa(rv); return rv; } /* * Javascript base64Decode() base64解密函数 用于解密base64加密的字符串 * 吴先成 www.51-n.com ohcc@163.com QQ:229256237 * @param string input base64加密字符串 * @return string 解密后的字符串 */ function base64Decode(input){ rv = window.atob(input); rv = escape(rv); rv = decodeURIComponent(rv); return rv; }
1,js索引数组定义
var dataArr= new Array(); dataArr["storeId"]=”15313 storeId”; dataArr["imgUrl"]=”123imgUrl”;
- [storeId: "15313 storeId", imgUrl: "123imgUrl"]
- imgUrl:"123imgUrl"
- storeId:"15313 storeId"
- length:0
2,删除最后一个字符
citys = citys.substr(0,citys.length-1);
3,跳转
window.location.href = "{:url('mobile/Login/logout')}"; window.location.reload();
2, form****表单外的提交
citys = citys.substr(0,citys.length-1);
<form class="clear" action="javascript:void(0);" id="baojia_form_message"> <label class="fl"><i class="iconfont icontouxiang"></i><input type="text" name="linkman" value="" placeholder="创始人"></label> <label class="fl"><i class="iconfont icondianhua"></i><input type="text" name="phone" value="" placeholder="联系电话"></label> <label class="fl"><i class="iconfont icondizhi"></i><input type="text" name="address" value="" placeholder="联系地址"></label> <label class="fl"><i class="iconfont iconlabel"></i><input type="text" name="entryname" value="" placeholder="项目名称"></label> <label class="fl"><i class="iconfont iconzijin"></i><input type="text" name="budget" value="" placeholder="融资资金"></label> <label class="fl"> <i class="iconfont iconzijin"></i><textarea name="yaoqiu" placeholder="融资资金留言"></textarea></label> </form> <article class="btn" > <input class="btn1" id="baojia_form_message_submit" value="提交"> </article> <script> $(document).ready(function (){ $('#baojia_form_message_submit').on("click", function(){ var options = { url: "{:url('home/Tuiguang/tijiao')}", type: 'post', dataType: 'json', data: $('#baojia_form_message').serialize(), success:function(data){ if (data.error = 1) { alert(data.msg); } }, error:function (){ alert("提交失败"); } }; $.ajax(options); return false; }) }); </script>
**2, form表单内**的提交
没写submit默认就用submit提交
<form action="javascript:void(0);" id="baojia_form_store"> <div class="name"> <input type="text" name="names" placeholder="您的称呼"> </div> <div class="phone"> <input type="number" name="phone" placeholder="手机号码(必填)"> </div> <div class="xiaoquname"> <input type="text" name="xiaoqu" placeholder="小区名称"> </div> <input type="hidden" value="官网报价精选案例详情页" name="searchtype"> <button>立即委托除醛</button> <p>为了您的利益及我们的口碑,您的隐私将被严格保密。</p> </form> <script> $(document).ready(function () { $('#baojia_form_store').bind("submit", function () { var options = { url: "{:url('home/Tuiguang/tijiao7')}", type: 'post', dataType: 'json', data: $('#baojia_form_store').serialize(), success: function (data) { if (data.error = 1) { alert(data.msg); } }, error: function () { alert("提交失败"); } }; $.ajax(options); return false; }) }); </script>
//js 替换$value字符串中<p>替换为空,</p>替换为<br/> $value = $value.replace(/<p>/g, ''); $value = $value.replace(/<\/p>/g, "<br\/>");
//获取div下面标签的值
//页面跳转
//导出 form.on('submit(export1)', function(data) { let key = ''; let localurl = "{:url('newplayer_list')}?"; for (key in data.field) { localurl += key + '=' + data.field[key] + '&'; } if (data.field.export_type1 === '1') { var this_page = $('#layui-table-page1').children("div").children("span").eq(0).text(); var this_limit =$('#layui-table-page1 select').find("option:selected").val(); localurl += '&page=' + this_page + '&limit=' + this_limit; } else { localurl += '&limit=-1'; } window.open(localurl + '&tplType=export'); // window.location.href = localurl + '&tplType=export1'; });
//添加和去除class id
$("#btn-primary-id" ).removeAttr('id'); $('.type-btn.btn-primary').removeClass('btn-default').addClass('btn-primary').attr("id","btn-primary-id");
使用jquery获取选中checkBox的同行数据
获取选中checkBox 所在行的数据。
这里以获取第三列和第四列数据为例子(除去checkBox列),会获取一列数据,就会获取一整行了。
实例图:
该页面代码:
打印选中数据: