<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>js</title>
<!-- 外部JS -->
<!-- <script src="js/new_file.js"></script> -->
<!-- 内部JS -->
<style>
p {
text-align: center;
}
span {
color: rgb(22, 241, 121);
}
div{
border: 1px solid red;
}
#div0{
width: 200px;
height: 200px;
}
#div2{
width: 100px;
height: 100px;
}
#div3{
width: 100px;
height: 100px;
}
.divh2{
color: #962cec;
}
</style>
</head>
<body>
<!-- <img id="star" src="img/1.jpg" width="100%"> -->
<!-- <p>
<span id="time">2</span>秒之后自动跳转到首页...
</p>
<input id="openBtn" type="button" value="打开窗口">;
<input type="button" id="btn" value="获取历史记录个数">
<div id="div1">div1</div>
<div class="cls1">div5</div>
<input type="text" name="username">
<a >点我</a>
<input type="button" id="btn_set" value="设置属性">
<input type="button" id="btn_remove" value="删除属性">
<div id="div0">
<div id="div2">div2</div>
div\</div>
<a href="javascript:void(0);" id="del">删除子节点</a>
<a href="javascript:void(0);" id="add">添加子节点</a>
<div id="divh">divh</div>
<div id="divh2">divh2</div> -->
<input type="text" id="blur">
<select id="change">
<option>选择</option>
<option>石家庄</option>
</select>
<script type="text/javascript">
// regExp();
// global();
// bom();
// bom1();
// bom2();
// dom();
// dom1();
// HTMLdom();
things();
//正则表达式对象
function regExp() {
var reg = /^\w{6,9}$/;
var userName = "robin";
var flag = reg.test(userName);
alert(flag);
}
function global() {
//编码
var str = "罗宾";
var E = encodeURIComponent(str);
var D = decodeURIComponent(E);
document.write(E + "<br />");
document.write(D);
//转数字
var str = "12sdc";
var num = parseInt(str);
document.write(num);
//判断NaN
var num1 = NaN;
document.write(isNaN(num1));
//解析
var str1 = document.write("robin");
eval(str1);
}
function bom(){
// history对象
var btn=document.getElementById("btn");
btn.οnclick=function(){
var length=history.length;
alert(length);
}
}
//轮播图
function bom1() {
var num1 = 1;
function fun() {
num1++;
if (num1 > 3) {
num1 = 1;
}
var getElementById = document.getElementById("star");
getElementById.src = "img/" + num1 + ".jpg";
}
setInterval(fun, 3000);
// confirm("确定返回true,反则");
// prompt("输入框");
// setTimeout(fun,2000);单次定时
// reload();刷新
// history.back();forword();length();
// go();加载具体页面 +-传参
function open() {
document.getElementById("openBtn");
}
}
//自动跳转首页
function bom2() {
var num = 2;
function show() {
num--;
if (num <= 0) {
location.href = "https://i.qq.com";
}
// var time=document.getElementById("time");
document.getElementById("time").innerHTML = num + "";//导入到body
}
setInterval(show, 1000);
}
function dom() {
// 获取element对象,返回数组
var divs = document.getElementsByTagName("div");
var div_cls = document.getElementsByClassName("cls1");
var ele_username = document.getElementsByName("username");
console.log(divs);
console.log(div_cls);
console.log(ele_username);
// 创建dom对象
// 设置属性
var table = document.createElement("table");
console.log(table);
// Element对象
var btn_set = document.getElementById("btn_set");
btn_set.onclick = function () {
var element_a = document.getElementsByTagName("a")[0];
element_a.setAttribute("href", "form.html")
// 删除属性
var btn_remove = document.getElementById("btn_remove");
btn_remove.onclick = function () {
var element_a = document.getElementsByTagName("a")[0];
element_a.removeAttribute("href")
}
}
// Node对象
var del=document.getElementById("del");
del.οnclick=function(){
var div0=document.getElementById("div0");
var div2=document.getElementById("div2");
div0.removeChild(div2);
}
var add=document.getElementById("add");
add.οnclick=function(){
var div0=document.getElementById("div0");
var div2=document.createElement("div");
div2.setAttribute("id","div2");
div0.appendChild(div2);
}
}
// 点切
function dom1() {
var star = document.getElementById("star");
var flag = false;
star.onclick = function () {
if (flag) {
star.src = "img/1.jpg";
flag = false;
} else {
star.src = "img/2.jpg";
flag = true;
}
}
}
function HTMLdom(){
var divh=document.getElementById("divh");
divh.innerHTML +="<input type='text'>";
// 样式
divh.οnclick=function(){
divh.style.border="5px solid red";
divh.style.fontSize="20px";
}
var divh2=document.getElementById("divh2");
divh2.οnclick=function(){
divh2.className="divh2";
}
}
function things(){
document.getElementById("blur").οnblur=function(){
document.write("lost");
}
document.getElementById("change").οnchange=function(){
alert("change");
}
}
</script>
</body>
</html>