首页 技术 正文
技术 2022年11月15日
0 收藏 417 点赞 3,612 浏览 2137 个字

1. js中this表示当前标签,获取当前标签内的属性,示例如下:

 var user_id = $(this).attr("data-user-id");

2.   * js中var定义变量的关键字

   * innerHTML 与 innerText修改内容

3.  document.write( ); 表示写入。

4. js中的比较运算符:

  && (与)     ||(或)   !(非)

5. 以下元素在判断时为假,其余任何都为真:

  0,null,undefined,NaN,‘ ’,false

6. js中的赋值运算符:

    ” += “  ” -= “  ” /= “  ” %= “  ” *= “

7. 判断运算符:

  在js中“ == ”:判断类型是否相等,

  而“ === ”:判断值和类型是否都相等。

8. 定时器:

   setTimeout  设置定时器    clearTimeout  清除定时器   setInterval   设置定时器    clearInterval    清除定时器

9. 在清除定时器的同时要给予定时器加个名字,便于赋值给清除定时器:

    定时器格式: setTimeout(函数.时间)

 #定时器
<script> setTimeout(function () {
// 延迟定时器 2000毫秒后执行一次
console.log(1);
},2000); // 1000毫秒 = 1s setInterval(function () {
// 隔1000毫秒后一直不停的在执行
console.log(2);
});
// 格式: setTimeout(函数,时间); function fn() {
console.log(3);
}
setTimeout(fn,2000);
</script> #清除定时器
<div id="box">
<p> 还有<span id="timer">5s</span>就开始! </p>
</div> <script>
var oTime = document.getElementById('timer');
var num = 5;
var time;
time = setInterval(function () {
num --; // 逐渐往下减
oTime.innerHTML = num +'s'; //打印
if(num === 1){
clearInterval(time);
// clearTimeout(time), 前面用哪个定时器后面就跟哪个,要一一对应
window.location.href = 'http://www.baidu.com';
// 去某个地方的固定写法
}
},1000);
</script>

10.  js中的for循环:

     # // for 循环
for(var i=0; i<6; i++){
if(i===3) break;
console.log(i);
if(i===3)continue;
console.log(i);
} var a=0;
# // 条件为真才会执行
while (a<6){
console.log(a);
a++;
} var b = 8;
# // 不管真假都会执行一次
do{
console.log(b);
}while (b>10);

11.  js中用于跳转:

 window.location.href = 'http://www.baidu.com';

12.    js 中用于刷新页面的是:

 window.location.reload();

13.  js执行事件:

     <div id="box1"></div>
<div id="box2"></div>
<script> var oBox1 = document.getElementById('box1');
var oBox2 = document.getElementById('box2'); // oBox1.onclick = function () {
// console.log(1); // 点击会打印1
// };
// oBox2.onclick = function () {
// console.log(1);
// }; function fn() {
console.log(1);
# // 设置值,可以直接调用
}
oBox1.onclick = fn; # // 如果加括号会自动执行, 一般不用
oBox2.onclick = fn;
</script>

14.  函数表达式:

         fn();
function fn() {
alert(1);
}; //函数定义 可以在定义前加括号执行,也可以在定义后加括号执行
// fn(); var fn = function () {
alert(1); // 通过var 的函数。只能在后面运行
}; // 效果一样
fn(); // 函数表达式
!function () {
alert(6)
}(); +function () {
alert(8)
}(); (function () {
alert(9)
})(); (function () {
alert(999) //国外使用方法,国内一般不用
}());

15.对样式进行修改:

       <div id="box"></div>
<script>
var box = document.getElementById('box');
box.style.width = "200px";
box.style.height = "120px";
box.style.marginTop = "20px";
box.style.marginLeft = "auto";
</script>
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,077
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,552
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,401
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,176
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,813
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,896