js----常用功能
1、切割
1. a="ddd" a.substr(0,1)
2、通过js找子代
document.getElementByClass("ddd").getElementByClass("ccc")
3、window.open
window.open( url,"n1","status=1, height:500, width:600, toolbar=0, resizeable=0"); #在当前也打开一个窗口,页面不刷新
window.open(url) #重新在开启一个窗口,之前的页面不刷新
window.opener使用
子页面要向父页面传值,只要在document前面加window.opener即可
window.opener.____ 后面调用的父页面的方法
例子
父页面
<body>
<h1 id = "a">无所谓</h1>
<a href="#" onclick=a("http://www.baidu.com")>点我点我</a>
<script>
function xxxpopupCallback(text) {
document.getElementById('a').innerHTML = text; //找到标签吧值替换成用户传进来的值
}
function a(url) {
window.open( '/pop/', "n1","status=1, height:500, width:600, toolbar=0, resizeable=0");
{#window.open( url,"n1","status=1, height:500, width:600, toolbar=0, resizeable=0");#}
}
</script>
</body>
子页面
<body>
<input type="text" name="user">
<button type="button" onclick="submit()">提交</button>
</body>
<script>
function submit() {
方法一
window.opener.document.getElementById("a").innerText=document.getElementsByTagName("input")[0].value #直接找到父页面的标签,进行替换值
方法二:
{#opener.xxxpopupCallback(document.getElementsByTagName("input")[0].value)#} #opener.xxxpopupCallback 调用父页面的xxxpopCallback 方法
window.close()
}
</script>
4、删除列表中的某个值
思路1:直接在delete上添加一个id属性(需要被删除的元素的id),通过js可以获取这个值,通过ajax发送异步请求,成功后,直接在页面上用js将他删除掉。
思路2:使用a标签包含一个butten按钮
思路2:使用form表单发送请求post请求,使用js方法(在js中创建表单,或者直接用页面上现有的表单进行submit())。
5、定时器
<script>
//每隔1秒执行function()
intervalId = setInterval(function () {
console.log(4);
}, 1000); //2秒之后执行function(),执行一次
setTimeout(function () {
//清除定时功能
clearInterval(intervalId)
},2000)
</script>
6、JS和Jquery获取input框中的值
<input type='text' id = 'username>'
var text = $(''#username").val("ddd") //jquery 获取值
$('username').val("") //jquery 设置值
var name = document.getElementById("CSDN_NAME").value //js获取值
7、数组的filter
var a = [1,2]
a.filter(res=>{return false}) -->a = []
a.filter(res=>{return true}) -->a = [1,2]
const accessedRouters = asyncRouterMap.filter(route => {
// console.log(route);
if (hasPermission(route)) {
if (route.children && route.children.length) {
route.children = filterAsyncRouter(route.children);
}
return true;
}
return false;
});
前端js/vue等的一些技巧
从后端取出来的数据,可以适当的对他进行编辑,比如添加一些字段show:true,方便自己操作
js----常用功能的更多相关文章
- JS 常用功能收集
JS 常用效果收集 1. 回到顶部>> 爱词霸
- js 常用功能实现(函数)
1.10 个短小实用的代码片段 :https://www.jianshu.com/p/3ef822ec5a63 2.js常用函数 : https://www.cnblogs.com/wangyuyu ...
- js常用功能汇总
var Utils = function() { this.Tools; this.ui; }; Utils = new Utils(); Utils.prototype.Tools = { year ...
- js - 常用功能方法汇总(updating...)
一.查值的类型(可用于拷贝) /* * @Author: guojufeng@ * @Date: 2017-12-20 15:07:06 * @purpose 获取一个值的类型 * @param {v ...
- JS常用功能
1.字符串转Json var json='[{"id":0,"text":"ddddd"},{"id":1," ...
- js常用功能总结
1,手机号的校验 //手机号的判断 function checktel() { //手机号不为空,格式校验 var tel = $(".uidbtp").val(); if(tel ...
- Hbuilder常用功能汇总
引用 样式表: mui.min.css Js:mui.min.js 常用功能 获取页面 var webView=plus.webview.currentWebview();//获取当前页 var we ...
- Google Chrome调试js代码,开发者工具之调试工具常用功能
参考:Google Chrome调试js代码-http://www.open-open.com/lib/view/open1384785324165.html 重点:左下角一个{}括号图标按钮用于把杂 ...
- 160229-01、web页面常用功能js实现
web页面常用功能js实现 1.网页未加载时弹出新窗口 <body onunload="window.open('http://www.a68.cn');">< ...
- es6常用功能与异步详解(JS高级面试题)
callback hell方法的使用 可读性不友好 function loadImg(src,callback,fail){ var img = document.createElement('img ...
随机推荐
- 数组去重的4种方法(Which one is the fastest???嘻嘻嘻....)
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Django REST framework 第三章 CBV
从介绍Django快开始,我们就一直在使用FBV的方式来撰写代码,二者本质上并没有太大的区别,然而到了REST framework,更会倾向于用CBV来写API的视图,后面会看到这个方式的强大,它允许 ...
- 【CentOS】Tomcat的安装
文件上传方式(推荐) # 解压 tar zxvf apache-tomcat-9.0.1.tar.gz # 进入bin目录启动 ./startup.sh # 进入log目录查看日志信息 tail -f ...
- 关于Scroller的使用
这篇文章讲解的很详细 https://blog.csdn.net/u011102153/article/details/53337648
- Tip:JSP标签也称之为Jsp Action(JSP动作)元素
JSP标签也称之为Jsp Action(JSP动作)元素,它用于在Jsp页面中提供业务逻辑功能,避免在JSP页面中直接编写java代码,造成jsp页面难以维护. ================ &l ...
- HashSet、TreeSet和LinkedHashSet分别基于HashMap、TreeMap和LinkedHashMap
1.如果你需要一个访问快速的Set,你应该使用HashSet: 当你需要一个排序的Set,你应该使用TreeSet: 当你需要记录下插入时的顺序时,你应该使用LinedHashSet. 2.因为Tre ...
- C语言中用于计算数组长度的函数 “strlen() ”。
de>#include<stdio.h>#include<stdlib.h>#define MAX_LEN 255int my_strlen1(const char* s ...
- LwIP Application Developers Manual4---传输层之UDP、TCP
1.前言 本文主要讲解传输层协议UDP TCP 2.UDP 2.1 UDP from an application perspective 2.2 UDP support history in lwI ...
- mysql使用group_by
GROUP BY必须得配合聚合函数来用,分组之后你可以计数(COUNT),求和(SUM),求平均数(AVG)等 常用聚合函数 count() 计数 sum() 求和 avg() 平均数 max() 最 ...
- localstorage实现网页状态记录比如放音乐功能的实例
<div class="music"> <a href="javascript:;" onclick="playPause();&q ...