一些公用的JS
2021-02-14 14:16
标签:nbsp and callback css play pen TBase get 阻止冒泡 一些公用的JS 标签:nbsp and callback css play pen TBase get 阻止冒泡 原文地址:https://www.cnblogs.com/Viagra/p/12992778.html/*阻止冒泡*/
function preventBubble(event){
var e=arguments.callee.caller.arguments[0]||event; //若省略此句,下面的e改为event,IE运行可以,但是其他浏览器就不兼容
if (e && e.stopPropagation) {
e.stopPropagation();
} else if (window.event) {
window.event.cancelBubble = true;
}
}
/*页面跳转*/
function go_page(url){
location.href = url
}
/*数组中按值删除*/
function removeByValue(arr, val) {
for(var i=0; i
/*判断两个数组是否相同*/
sameArray: function(arr1, arr2) {
if (arr1.length == arr2.length) {
var arr3 = [];
for (var key in arr1) {
var stra = arr1[key];
var count = 0;
for (var j = 0; j ) {
var strb = arr2[j];
if (stra == strb) {
count++;
}
}
if (count === 0) { //表示数组1的这个值没有重复的,放到arr3列表中
arr3.push(stra);
}
}
if (arr3 != []) {
return true
} else {
return false
}
} else {
return false
}
},
// beta64方法
getBase64: function(file, callback) {
var maxWidth = 640;
if (file.files && file.files[0]) {
var thisFile = file.files[0];
if (thisFile.size > 2019200) {
// mualert.alertBox("图片不能超过800K");
alert("2M以内の画像を選択してください!");
return
};
var reader = new FileReader();
reader.onload = function(event) {
var imgUrl = event.target.result;
var img = new Image();
img.onload = function() {
var canvasId = ‘canvasBase64Imgid‘,
canvas = document.getElementById(canvasId);
if (canvas != null) { document.body.removeChild(canvas); }
var canvas = document.createElement("canvas");
canvas.innerHTML = ‘New Canvas‘;
canvas.setAttribute("id", canvasId);
canvas.style.display = ‘none‘;
document.body.appendChild(canvas);
canvas.width = this.width;
canvas.height = this.height;
var imageWidth = this.width,
imageHeight = this.height;
if (this.width > maxWidth) {
imageWidth = maxWidth;
imageHeight = this.height * maxWidth / this.width;
canvas.width = imageWidth;
canvas.height = imageHeight;
}
var context = canvas.getContext(‘2d‘);
context.clearRect(0, 0, imageWidth, imageHeight);
context.drawImage(this, 0, 0, imageWidth, imageHeight);
var base64 = canvas.toDataURL(‘image/png‘, 1);
var imgbase = base64.substr(22);
callback(imgbase)
//this.imgUrl =
}
img.src = imgUrl;
}
reader.readAsDataURL(file.files[0]);
}
},
// 数组比较,输出不同,A数组为max数组
array_comparison: function(array, array2) {
var arr3 = [];
for (key in array) {
var stra = array[key];
var count = 0;
for (var j = 0; j ) {
var strb = array2[j];
if (stra == strb) {
count++;
}
}
if (count === 0) { //表示数组1的这个值没有重复的,放到arr3列表中
arr3.push(stra);
}
}
return arr3
},
//
Sort_by_date:function(data_list,orderType){
for(var index in data_list){
let time_arr = data_list[index].date.split(".")
let time_nums = time_arr.length
let times = null
if(time_nums==1){
let year = time_arr[0]
times = Number(year)*10000
}
if(time_nums==2){
let year = time_arr[0]
let mouth = time_arr[1]
if(mouth){
mouth = ‘0‘ + mouth
}
times = Number(year)*10000 + Number(mouth)*100
}
if(time_nums==3){
let year = time_arr[0]
let mouth = time_arr[1]
let day = time_arr[2]
if(mouth){
mouth = ‘0‘ + mouth
}
if(day){
day = ‘0‘ + day
}
times = Number(year)*10000 + Number(mouth)*100 + Number(day)*1
}
data_list[index][‘temp_date_num‘] = times
}
if (orderType!==0){
data_list.sort(function (p1,p2) {
//如果返回负数,p1在前,返回正数,p2在前
//1代表升序,2代表降序
if (orderType===2){
return p2.temp_date_num-p1.temp_date_num;
} else {
return p1.temp_date_num-p2.temp_date_num;
}
})
}
return data_list;
},
Sort_by_date_mouth:function(data_list,orderType){
for(var index in data_list){
let time_arr = data_list[index].year_month.split(".")
let year = time_arr[0]
let mouth = time_arr[1]
if(mouth){
mouth = ‘0‘ + mouth
}
let times = Number(year)*10000 + Number(mouth)*100
data_list[index][‘temp_date_num‘] = times
}
if (orderType!==0){
data_list.sort(function (p1,p2) {
//如果返回负数,p1在前,返回正数,p2在前
//1代表升序,2代表降序
if (orderType===2){
return p2.temp_date_num-p1.temp_date_num;
} else {
return p1.temp_date_num-p2.temp_date_num;
}
})
}
return data_list;
},
//对数组进行去重
Array_deduplication: function(arr){
var new_arr=[];
for(var i=0;i
*/
function Scroll_bar_widening(ul,title){
setTimeout(() => {
$("."+ul).scrollTop(10);//控制滚动条下移10px
if( $("."+ul).scrollTop()>0 ){
$("."+title).css({
"padding-right": ‘17px‘
})
}else{
$("."+title).css({
"padding-right": ‘0‘
})
}
$("."+ul).scrollTop(0);//滚动条返回顶部
}, 100);
}