判断客户端,然后打开已经安装的app (安卓系统下)
- var isIDevicePhone = (/iphone|ipod/gi).test(navigator.userAgent);
- var isIDeviceIpad = !isIDevicePhone && (/ipad/gi).test(navigator.userAgent);
- var isIDevice = isIDevicePhone || isIDeviceIpad;
- var isAndroid = !isIDevice && (/android/gi).test(navigator.userAgent);
- var ua = navigator.userAgent.toLowerCase();
- var isWeixin = ua.match(/micromessenger/gi);
- if(isAndroid && !isWeixin) {
- window.location="nihao://nihao";//打开某手机上的某个app应用
- }
-
- <intent-filter>
- <action android:name="android.intent.action.VIEW" />
- <category android:name="android.intent.category.BROWSABLE" />
- <category android:name="android.intent.category.DEFAULT"/>
- <data android:scheme="nihao" android:pathPrefix="/nihao" />
- </intent-filter>
mongodb的属性为对象的字段property,对property对象里再次添加一些属性,并将属性赋值
- 遍历property对象的属性(名称为汉字的方法) property[item]
- 根据_id查询条件修改property
- var person = db.getCollection("").find({});
-
- person.forEach( function(event) {
- print(event.variables.recordId + " "+ event.word);
- var property;
- db.getCollection( "").find({ "recordId":NumberLong(event.variables.recordId)}).forEach(function(n) {
- property = n.property;
- property.recordId=event.variables.recordId;
- property.rate=event.variables.rate;
- property[ "简介"] = n.introduction;
- });
-
- for(var item in property) {
- print(property[item]);
- }
- db.getCollection( "").update({ '_id':event._id}, { $set:{ 'property':property, "del":"1"}})
- });
将一个表的数据保存到另一张表中,相比较save和insert方法
- insert: 若新增数据的主键_id已经存在,则会抛 org.springframework.dao.DuplicateKeyException 异常提示主键重复,不保存当前数据。
- save: 若新增数据的主键_id已经存在,则会对当前已经存在的数据进行修改操作。
- var notin = db.getCollection("").find({});
-
- notin.forEach( function (event) {
- print( "notin_bak _id-->" + event._id + " word--> " + event.word);
- db.getCollection( "").save(event);
-
- });
将一个表的数据保存到另一张表中,如何另一张表的word与一个表的word相同,就不保存。也就是保存在另一张表中不存在word的方法
- var find = db.getCollection("").find({});
-
- find.forEach( function(event) {
- var flag = true;
- db.getCollection( "").find({ "word":event.name}).forEach(function(n) {
- flag = false;
- db.getCollection( "").save(event);
- });
-
- if(flag) {
- db.getCollection( "").save(event);
- }
- });
查询属性不存在 [ "运动项目", "生肖", "星座", "血型"]的字段的方法
indexof是判断一个数组是否含有某个元素的方法,不存在的返回-1
-
- var find = db.getCollection("").find({ "category": /.*人物.*/i });
-
- var persongArray = [ "运动项目", "生肖", "星座", "血型"];
-
-
- find.forEach( function(event) {
- print( "_id"+ event._id + " word " +event.word);
- var errorcount = 0;
- for(var item in event.variables) {
- //词典表中的字段
-
- if(persongArray.indexOf(item) < 0) {
- print(item);
- errorcount++;
- }
- // print(persongArray.indexOf(item));
- }
- print( "不匹配字段数目:" + errorcount + "\n");
- });
打开一个app,如果打不开则跳转到另一个页面
- function isInstalled(){
- /*var the_href="https://mobile.baidu.com/item?docid=24307148&source=pc";//获得下载链接
- window.location="nihao://nihao";//打开某手机上的某个app应用,在intent-filter里面,由安卓客户端同事提供
- setTimeout(function(){
- window.location=the_href;//如果超时就跳转到app下载页
- },500);*/
- var loadDateTime = new Date();
- window.location = "nihao://nihao"; //打开app的协议,在
- setTimeout( function () {
- var timeOutDateTime = new Date();
- if (!loadDateTime || timeOutDateTime - loadDateTime < 1510) {
- window.location = ""; //如果超时就跳转到app下载页
- }
- }, 1500);
- }
- <intent-filter>
- <action android:name="android.intent.action.VIEW" />
- <category android:name="android.intent.category.BROWSABLE" />
- <category android:name="android.intent.category.DEFAULT"/>
- <data android:scheme="nihao" android:pathPrefix="/nihao" />
- </intent-filter>
jquery将一些题目打印出控制台中,类似于一个爬虫爬取内容
- for(var i=2; i<=13;i++) {
-
- window.location.href="https://www.zhiliti.com.cn/html/changshiti/list22_"+i+".html"
- var anniu;
- for(var i=0; i<$(".list").find("li a").size(); i++) {
- var titleStr = $(".list").find("li a").get(i).title;
- $( ".list").find("li span").get(i).onclick();
- var answerStr = $(".anniu").get(i).innerHTML.replace("答案:","");
- anniu += "Q:" + titleStr +"\n A:"+ answerStr+"\n\n";
- }
- console.log(anniu);
-
- }
js将sring转为json js将json转为string
- var jsonobj = JSON.parse(str) //将string转为json
-
- var last=obj.toJSONString(); //将JSON对象转化为JSON字符
- var last=JSON.stringify(obj); //将JSON对象转化为JSON字符
js将string转为int
发现parseInt方法在format'00'开头的数字时会当作2进制转10进制的方法进行转换,所以建议string转int最好用Number方法
- parseInt(str) //将str的string类型转为int
-
- Number(str) //建议使用这种
js操作json对象,删除对象中一个属性,也就是删除一个key:value
delete singer.name //这样的话 singer中的 "name":"周杰伦" 这个键值对就被干掉了