- HTML 鼠標(biāo)碰到div內(nèi)元素、離開div內(nèi)元素觸發(fā) mouseover mouseout事件
可用jquery的 mouseleave 和 mouseenter 事件避免這種情況
- 向數(shù)組中首項(xiàng)添加數(shù)據(jù)
unshift()
GPS坐標(biāo)定義
WGS-84:是國際標(biāo)準(zhǔn),GPS坐標(biāo)(Google Earth使用、或者GPS模塊)
GCJ-02:中國坐標(biāo)偏移標(biāo)準(zhǔn),Google Map、高德、騰訊使用
BD-09:百度坐標(biāo)偏移標(biāo)準(zhǔn),Baidu Map使用
拼接對象集合中的,某一項(xiàng)屬性
var items = [{name:'abc'},{name:'123'},{name:'!@#'}]
items.map(function(item){return item.name}).join(',');
輸出 "abc,123,!@#"
解決html中l(wèi)abel 或 span 無法設(shè)置width
{display:inline-block;}
select2寬度根據(jù)內(nèi)容自適應(yīng)
$("#select_demo").select2({width: "resolve"});
select2獲取選中項(xiàng)的內(nèi)容
$("#status").select2("data")[0].text;
解決vue渲染中,頁面顯示源碼問題
1. 添加樣式
[v-cloak]{
display: none;
}
2.在vue元素上添加 v-cloak屬性
或用template標(biāo)簽將需要渲染的html包起來
判斷元素是否顯示
$("#div").is(":hidden"); // 判斷是否隱藏
$("#div").is(":visible") //是否顯示
帶有表單的頁面,防止按回車頁面刷新
$('form').on('submit', function () {
return false;
});
動態(tài)改變URL但是頁面不跳轉(zhuǎn)
var stateObject = {};
var title = "Wow Title";
var newUrl = "/my/awesome/url";
history.pushState(stateObject,title,newUrl);
模態(tài)窗口顯示、隱藏 事件
$('#myModal').on('shown.bs.modal', function (e) {
xxxxxx
$('#myModal').off('shown.bs.modal');//執(zhí)行完XXX后解綁,防止后面綁定其他方法還會執(zhí)行XXX
})
$('#myModal').on('hidden.bs.modal', function (e) {
xxxxxx
$('#myModal').off('hidden.bs.modal');
})
清空jqgrid內(nèi)容
jQuery("#table_passenger_list").jqGrid("clearGridData");
jqgrid取消選中
("#table_list").jqGrid('resetSelection');
jqgrid 選中某一行
$("#table_list").jqGrid('setSelection', rowId);
CSS設(shè)置屬性選擇器
# 帶title屬性的
[title]
{
color:red;
}
# 帶title屬性且title = W3School的
[title=W3School]
{
border:5px solid blue;
}
js post提交下載請求
function download() {
var form = $('<form>');
form.attr("style", "display:none");
form.attr("target", "_blank");
form.attr("method", "post");
form.attr("action", window.location.href.substring(0,window.location.href.lastIndexOf("/"))+"/seatOccupancyExport.json");
var starDate = $('<input>');
starDate.attr("type", "hidden");
starDate.attr("name", "startDate");
starDate.attr("value", $('#text_searchStartDate').val());
var endDate = $('<input>');
endDate.attr("type", "hidden");
endDate.attr("name", "endDate");
endDate.attr("value", $('#text_searchEndDate').val());
var routeParentIdList = $('<input>');
routeParentIdList.attr("type", "hidden");
routeParentIdList.attr("name", "routeParentIdList");
routeParentIdList.attr("value", $("#sel_route").val());
var routeIdList = $('<input>')
routeIdList.attr("type", "hidden");
routeIdList.attr("name", "routeIdList");
routeIdList.attr("value", getMultiSelectedRouteTimes().routeTimesValues);
$('body').append(form);
form.append(starDate);
form.append(endDate);
form.append(routeParentIdList);
form.append(routeIdList);
form.submit();
form.remove();
}
獲取jquery元素自身html代碼
$(".test").prop("outerHTML")
替換字符串
'12123456'.replace(new RegExp('1'),'a')
"a2123456"
替換全部
'12123456'.replace(new RegExp('1','g'),'a')
"a2a23456"
div高度隨著瀏覽器改變而改變
window.onresize = function () {
$('#div_map').css('height', (document.body.clientHeight) + 'px');
}
JS集合 過濾符合條件的數(shù)據(jù)
colors = colors.filter(function(item) {
return item != "red"
});
返回所有非red內(nèi)容集合
Vue 點(diǎn)擊事件中,獲取當(dāng)前控件
@change="checkChange($event)"
checkChange: function(e){ e.target}

image.png