1.文字兩端居中
text-align:justify;
text-justify:distribute-all-lines;/*ie6-8*/
text-align-last:justify;/* ie9*/
-moz-text-align-last:justify;/*ff*/
-webkit-text-align-last:justify;/*chrome 20+*/
2.多個(gè)異步請(qǐng)求的執(zhí)行順序
點(diǎn)擊頁(yè)面上一個(gè)按鈕發(fā)送兩個(gè)ajax請(qǐng)求時(shí),這兩個(gè)異步請(qǐng)求會(huì)同時(shí)發(fā)送,至于執(zhí)行的快與慢,要看響應(yīng)的數(shù)據(jù)量的大小及后臺(tái)邏輯的復(fù)雜程度
當(dāng)一個(gè)異步請(qǐng)求發(fā)送時(shí),瀏覽器不會(huì)處于鎖死、等待的狀態(tài),從一個(gè)異步請(qǐng)求發(fā)送到獲取響應(yīng)結(jié)果的期間,瀏覽器還可以進(jìn)行其它的操作。這就意味著多個(gè)異步請(qǐng)求的執(zhí)行時(shí)并行的
所以要想使其按一定順序執(zhí)行,解決方案:參考
- Ajax2()方法的執(zhí)行放到Ajax1()的success回調(diào)函數(shù)的最后一行。
- Ajax1()的異步請(qǐng)求方法中,增加一個(gè)回調(diào)函數(shù) :complete : Ajax2
3.限制字?jǐn)?shù)
overflow:hidden;
text-overflow:ellipsis;
white-space:nowrap;
4.獲取驗(yàn)證碼(正???
獲取接口并計(jì)時(shí):
頁(yè)面
<div class="check">
<label>驗(yàn)證碼</label>
<input type="text" placeholder="請(qǐng)輸入驗(yàn)證碼" id="code">
<span class="get_code" onclick="sms_send()" id="getCode" style="display:none;">發(fā)送驗(yàn)證碼</span>
</div>
<p class="msg"></p>
JS
// 點(diǎn)擊獲取驗(yàn)證碼
var InterValObj; //timer變量,控制時(shí)間
var count = 60; //間隔函數(shù),1秒執(zhí)行
var curCount;//當(dāng)前剩余秒數(shù)
var sms_code = ""; //驗(yàn)證碼
var codeLength = 4;//驗(yàn)證碼長(zhǎng)度
function sms_send(){
$(".msg").empty(); //先將提示文字清空
curCount = count;
var phone = $(".g_phone #tel").val();//手機(jī)號(hào)碼
var reg = /^1[34578]\d{9}$/;
if (phone == "") {
$(".msg").text("請(qǐng)?zhí)顚?xiě)手機(jī)號(hào)");
} else if (!reg.test(phone)){
$(".msg").text("請(qǐng)?zhí)顚?xiě)正確的手機(jī)號(hào)碼!");
}else{
for (var i = 0; i < codeLength; i++) {
sms_code += parseInt(Math.random() * 9).toString();
}
$.ajax({
type: 'POST',
url: "/index/login/sms_code",
dataType: 'json',
data: {
sms_code: sms_code,
phone: phone
},
error: function () {
$(".msg").text('發(fā)送失敗,請(qǐng)稍后重試!');
},
success: function (data) {
if (data.ret== 200) {
$(".g_phone #getCode").css("cursor", "default");
$(".g_phone #getCode").removeAttr("onclick");
$(".g_phone #getCode").hide();
$(".g_phone #time").show().text(curCount + "秒");
InterValObj = window.setInterval(SetRemainTime, 1000); //啟動(dòng)計(jì)時(shí)器,1秒執(zhí)行一次
} else {
$(".msg").text(data.msg);
}
}
})
}
}
function SetRemainTime() {
if (curCount == 0) {
window.clearInterval(InterValObj);//停止計(jì)時(shí)器
$(".g_phone #getCode").show();
$(".g_phone #time").hide();
$(".g_phone #getCode").css("cursor", "pointer");//啟用按鈕
$(".g_phone #getCode").attr("onclick", "sms_send()");
$(".g_phone #getCode").text("重新發(fā)送");
sms_code="";
}
else {
curCount--;
$(".g_phone #getCode").hide();
$(".g_phone #time").show().text(curCount + "秒");
}
}
5.調(diào)用微信接口上傳圖片
①頁(yè)面中</body>前引入以下兩個(gè)JS,用途是連接微信授權(quán)獲取token,只有這樣才能有權(quán)限上傳圖片
<script src="http://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
<script src="http://zxk.xuanxuepai.com/weixin/index.php"></script>
②加入以下JS方法,只需要修改①②③三個(gè)注釋的地方即可
function img_upload() { //①方法名稱(chēng)隨意,需要上傳圖片的時(shí)候onclick這個(gè)方法就行了
wx.chooseImage({
count: 1,
sizeType: ['original', 'compressed'],
sourceType: ['album', 'camera'],
success: function (res) {
var localIds = res.localIds[0];
wx.uploadImage({
localId: localIds,
isShowProgressTips: 1,
success: function (res) {
var serverId = res.serverId;
$.ajax({
type: 'POST',
url: "", //②此處寫(xiě)上傳接口
dataType: 'json',
data: {
media_id: serverId
},
error: function () {
layer.msg('網(wǎng)絡(luò)錯(cuò)誤,請(qǐng)稍后再試!');
},
success: function (data) {
if (data.ret == 200) {
//③成功后的回調(diào),data,data里返回了用戶剛剛上傳的圖片的地址
} else {
layer.msg(data.msg);
}
}
})
}
});
}
});
}
6.刷新頁(yè)面
- 異步請(qǐng)求成功后延時(shí)跳轉(zhuǎn)頁(yè)面
window.setTimeout('window.location.href="/index/index/index";',2000) - 頁(yè)面的刷新
setTimeout("parent.location.reload();",2000);
window.location.reload()
7.layui相關(guān)問(wèn)題
- 表單按第幾個(gè)排序
$(document).ready(function () { $('.dataTables-example').dataTable({ "aaSorting": [ 6,"desc" ] }); }); - 頁(yè)數(shù)
要放在頁(yè)面渲染完成后$(document).ready(function () { $(".dataTables-example").dataTable(); });
8.em rem的單位問(wèn)題
em要將body的font-size設(shè)為62.5%
rem要將html的font-size設(shè)為62.5%
測(cè)得字體直接/10即可