编程笔记第一节

1,应用magin;0 auto;时,先保证在前,其他margin在后才能生效。如:margin: 0 auto;margin-top: 30upx;
2、随机数生成函数:

random(minNum,maxNum){
	switch(arguments.length){ 
		case 1: 
			return parseInt(Math.random()*minNum+1,10); 
		break; 
		case 2: 
			return parseInt(Math.random()*(maxNum-minNum+1)+minNum,10); 
		break; 
			default: 
				return 0; 
			break; 
	} 
}

3、替换函数str.replace(/\/g,’’)把所有的‘\’替换为空。
4、 ( ′ w i n d o n ′ ) . r e a d y ( f u n c t i o n ( ) ) 窗 口 加 载 完 成 5 、 ('windon').ready(function(){})窗口加载完成 5、 (windon).ready(function())5(‘document’).ready(function(){})文档加载完成
6、一个复制函数

function copy(s){
			if(window.clipboardData){
				window.clipboardData.setData("text",s);
			}else{
				(function(s){
		 			document.oncopy=function(e){
		    		e.clipboardData.setData("text",s);
		    		e.preventDefault();
		    		document.oncopy=null;
		 		}
			})(s);
				document.execCommand("Copy");
			}
		}

7、绘制图片和文字生成海报的小demo

<script type="text/javascript">
		//获取页面宽度高度和画板的尺寸
		var win_h,win_w,home_h,home_w,nickname,fonts;
		nickname = "王子"
		
		$(document).ready(function(){			
			setTimeout(()=>{
				$.hideLoading();
			},2000)
			//基础设置
			win_w = $(window).width();
			win_h = $(window).height();
			console.log(win_w,win_h);
			home_w = $('.home').css("width");
			home_h = $('.home').css("height");
			console.log(home_w);
            //设置随机数
			$(".fenx span").text(random(120000,500000))
			
			
			
			var url1 = "http://XXXXXX/addons/xiandi_iq/template/mobile/common/image/haibao/1.jpg"
			var url2 = "https://wx.qlogo.cn/mmopen/vi_32/tQTicYLeq4icmGWyd95tXUAZt7ibMpWqAvt2Df8MykLtfJM2D1oN5rueJno94qkSZeFLDlkha2MxFWzWn0y8AdgIA/132"
			var dataURL = ''
			img1 = new Image()
			img1.setAttribute('crossorigin', 'anonymous')
			img1.src = url1
			var cvs = document.getElementById("mycvs")
			img1.onload = function(){
				var w1 = parseInt(home_w.replace("px",""))*2//设置宽为画板的宽度
				var h1 = win_h*0.7*2//设置高为屏幕的0.7倍
				cvs.width = w1
				cvs.height = h1
				cvs.getContext("2d").drawImage(img1, 0, 0, w1, h1)
				// dataURL = cvs.toDataURL("image/png", 1)
				// console.log(dataURL)
				img2 = new Image();
				img2.setAttribute('crossorigin', 'anonymous');
				img2.src = url2;
				img2.onload=()=>{
					cvs.getContext("2d").drawImage(img2, win_w*0.05*2, win_h*0.11*2,win_w*0.15*2, win_h*0.08*2);
					cvs.getContext("2d").font = "bold 28px arial";
					cvs.getContext("2d").fillText(nickname,win_w*0.35*2,win_h*0.135*2);
					dataURL = cvs.toDataURL("image/png", 1)
					// console.log(dataURL)  //绘制成功
					$(".home").html("<img src='"+dataURL+"' style='width: 100%;height: 100%;'>")//输出在页面中
					$(".fenx").css("font-size",win_w/30);
					$(".show").show();
				}
			}
			
		})
		
		function random(minNum,maxNum){
			switch(arguments.length){ 
				case 1: 
					return parseInt(Math.random()*minNum+1,10); 
				break; 
				case 2: 
					return parseInt(Math.random()*(maxNum-minNum+1)+minNum,10); 
				break; 
					default: 
						return 0; 
					break; 
			} 
		}		
	</script>

8、jquery中几个重要的东东
$().val()取置value值
$().html()取置html值
$().text()取置文本
$().css()取置css
$().attr()取值属性
( ) . m o v e A t t r i ( ) 移 除 属 性 9 、 设 置 显 示 与 隐 藏 首 先 可 以 用 d i s p l a y : n o n e 设 置 元 素 不 显 示 , 相 当 于 是 不 渲 染 , 再 用 ().moveAttri()移除属性 9、设置显示与隐藏 首先可以用display:none设置元素不显示,相当于是不渲染,再用 ().moveAttri()9displaynone().show()显示出来
10、网页之间的跳转适用于uniH5编译
windown.location.href = “url”
11、文字两端对齐的方法
text-align:justify;
text-align-last:justify;
前提是不能有flex布局
12.reg.test(“字符串”) 返回布尔类型
13、uniapp中请求用get,data参数直接写成data: {jigou,pickerName,pickerCode,custName,custCode,phone},
14、align-self: flex-end;可以让文字靠下
15、省略号配置:

         overflow: hidden;
		text-overflow:ellipsis;
		white-space: nowrap;

16、小程序背景固定的方法:

		position: absolute;
		width: 100%;
		height: 100%;
		position: fixed;

17、小程序设置背景方法二:

		background-image: url(http://xxxx.com/bk.jpg);
		background-size: 100% 100%;
		width: 100%;
		height: 100%;
		position: fixed;

18、设置输入框输入的距离

		.inpt input{
			padding-left: 40upx;
		}

19、元素设置position之后,元素会浮动起来,同时left,right等属性激活,
他总是相对于最近的position元素定位,与此同时margin失效。
20、循环元素中不能用position否则会循环失效
21、数组去重复let newArr2 = […new Set(newArr)];
22、this.navData[“这里面不能有this.XXX”]
23、this.navData.unshift(“全国”)在开头添加元素与push相反
23、利用filter函数过滤数据:

let filterList =  this.list.filter((item,index,arr)=>{
		return item.province == navName;
	})

24、对于筛选数据来说,请求回来的数据不用同过nav多次请求,只需把请求回的回去现存放到缓存中再利用

uni.getStorage({
		 key: 'storage_list',
		 success:(res)=>{
			 this.list = res.data.filter((item,index,arr)=>{
					return item.province == navName;
			 })
		 }
	 });

25、页面之间数据传递:
1.用全局变量
2.使用路径&xxx携带数据,再通过下一个页面的onload(option)中的option提现
3.使用数据缓存,uni.setStorage(),在下一个页面中的onShow(option)的option提现
26、es6中map()函数是用来整理数据用的

 let newArr = this.list.map((item,index,arr)=>{
	 	let wlProvince = item.province;
	 	return wlProvince;
	 })
	 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

中兴之路

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值