您的位置:首页 > 财经 > 产业 > app下载安装安卓版_京icp备号在线查询_app运营推广策划方案_海外推广

app下载安装安卓版_京icp备号在线查询_app运营推广策划方案_海外推广

2025/5/10 6:10:35 来源:https://blog.csdn.net/WuMingf_/article/details/144171128  浏览:    关键词:app下载安装安卓版_京icp备号在线查询_app运营推广策划方案_海外推广
app下载安装安卓版_京icp备号在线查询_app运营推广策划方案_海外推广

1.JavaScript 基本使用

2.JavaScript简单事件

3.JavaScript修改样式

4.JavaScript数据类型

JavaScript和Java有什么关系

知识点一 JavaScript基本使用 

JS写在哪 

还有一种写在中间的,也就是<head>里面 

JS一些注意事项 

 JS修改元素内容

#JS获取对象<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title>Title</title>
</head>
<body><div class="box" id="box1">你好,世界</div><div class="box">捡起大王</div><input type="text" name="hello" placeholder="在坐的都是弟弟"><script>// 变量Idvar Id = document.getElementById('box1');console.log(Id);Id.innerText = 'hello world';//classvar Class = document.getElementsByClassName('box')[1];console.log(Class);Class.innerText = '捡起大王666';// 标签var None = document.getElementsByTagName('div')[0];console.log(None);//namevar Myname = document.getElementsByName('hello');console.log(Myname)//css选择器//取到直接返回,不会往下取var Select = document.querySelector('.box');console.log(Select);//取全部var Select = document.querySelectorAll('.box');console.log(Select);var Select = document.querySelectorAll('#box1');console.log(Select);</script>
</body>
</html>

 知识点二 JS简单事件

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title>Title</title><style>div{width: 200px;height: 200px;background: purple;}</style>
</head>
<body><div id="box"></div><select name="" id=""><option value="nj">南京</option><option value="sj">苏州</option><option value="cz">常州</option></select><script>/*事件 是指JavaScript 捕获到用户的操作,并作出正确的响应。在事件的数中,有一个关键字this,代表当前触发事件的这个元素事件  用户操作元素  事件=函致鼠标事件:左键单击  onclick左键双击  ondblclick鼠标移入  onmouseover/onmouseenter ***鼠标移出  onmouseout/onnouseleave  ****/var oBox = document.getElementById('box');oBox.onclick = function (){this.innerHTML = '我被点击了'};oBox.ondblclick = function (){this.innerHTML = '我被双击了'};oBox.onmouseover = function (){this.innerHTML = '鼠标移入'this.style.backgroundColor = 'blue'};oBox.onmouseout = function (){this.innerHTML = '鼠标移出'this.style.backgroundColor = 'red'};window.onresize = function (){console.log('我在变化')}var sel = document.querySelector('select');sel.onchange = function (){console.log('下拉选择在变化')}</script>
</body>
</html>

 知识点三 修改样式

修改样式

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title>Title</title>
</head>
<body><input type="text" id="box1" value="捡起"><div id="box" style="width: 100px;height: 100px;background: red"></div><script>var oBox = document.getElementById('box')// oBox.style.width = '50px';oBox.onclick = function (){// oBox.style.width = '400px';// oBox.style.height = '400px';// oBox.style.background = 'blue'oBox.style.cssText = 'width:400px;height:400px;background:yellow'};oBox.style.marginLeft = '100px';oBox.style['margin-left'] = '50px';oBox.style['width'] = '400px';var a = 'width';var b = '300px';oBox.style['a'] = 'b';var In = document.getElementById('box1').valuealert(In)</script>
</body>
</html>

JS操作标签属性

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title>Title</title>
</head>
<body><a href="http://baidu.com" id="box" xy = 'jianqi' target="_blank" class="wrap">去百度</a>
<script>/*js操作元素的标签属性:input 标签 value规范的标签属性:. 符号直接操作 (可读可写)不规范(自定义)的标签属性获取.getAttribute()设置.setAttribute()移除.removeAttribute()注意:所有的 路径 颜色 获取 的结果不一定是你写的内容通过Id获取的元素赋值给变量后,假设修改了Id,这个变量还是表示这个元素自定义标签属性的操作方式,同样可以操作符合规范的属性*/var oA = document.getElementById('box');oA.target = "_self";// oA.href = 'http://vip.com';// alert(oA.id)// alert(oA.className)alert(oA.getAttribute('xy'));oA.setAttribute('xy','fufu');alert(oA.getAttribute('xy'));oA.removeAttribute('xy');alert(oA.getAttribute('xy'));
</script>
</body>
</html>

 知识点四 JavaScript数据类型

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title>Title</title>
</head>
<body><script>// stringconsole.log(typeof'8');// numberconsole.log(typeof 1234.11);// booleanconsole.log(typeof true);// objectconsole.log(typeof [1,2,3,4,5]);console.log(typeof {name:'jianqi'});console.log(typeof []);console.log(typeof null);function f() {}console.log(typeof f);// undefinedvar y;console.log(typeof y);var v = Symbol(1234);console.log(typeof v);</script>
</body>
</html>

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com