JS(三)
来源:互联网 发布:mac终端建立文件夹 编辑:程序博客网 时间:2024/06/12 03:18
函数: body:
分别赋值输出,再一起输出
function forin() { <input type="button" onclick="forin()" value="forin"/>var person={fname:"张",lname:"三",age:"66"};
var cc="";
for(i in person){
cc=cc+person[i];
alert(cc);
}
}
函数: body:function test1() { <input type="button" onclick="test1()" value="1"/>
shuzu=["1","2","3","33"];
var i=0;
for(;shuzu[i];){
document.write(shuzu[i]+"<br>")
i++;
}
}
----------------------------------------------------------------------------------------------------------------------------------------------------------
函数: body:
通过标签找到对象 ,原理同id相同。
function test2() { <input type="button" onclick="test2()" value="2"/>
var a=document.getElementsByTagName("p");
alert(a.length);
for(var i=0;i<a.length;i++){
alert(a[i].id);
}
}
----------------------------------------------------------------------------------------------------------------------------------------------------------
函数: body:
通过id找到次标签内部的某个标签
function test3() { <div id="A"> <p id="a"></p><p id="b"></p> </div>
var b=document.getElementById("A")
var a=b.getElementsByTagName("p");
alert(a.length);
for(var i=0;i<a.length;i++){
alert(a[i].id);
}
}
----------------------------------------------------------------------------------------------------------------------------------------------------------
函数: body:
JQ通过ID查找value并输出值
function test4() {//JQ写; <input id="aa" type="button" onclick="test4()" value="4"/>
var a=$("#aa").val();
alert(a);
}
----------------------------------------------------------------------------------------------------------------------------------------------------------
函数: body:
匿名函数另一种写法
document.getElementById("cc").onclick=function(){dayte()} <input id="cc" type="button" onclick="test6()" value="6"/>
function dayte() {
alert("qq");
}
----------------------------------------------------------------------------------------------------------------------------------------------------------
函数: body:
鼠标放上去、离开产生效果
function over(obj) { <div id="mouse1" onmouseover="over(this)" onmouseout="out(this)" onmousedown="down()"onmouseup="up()">离开</div>
obj.innerHTML="放在上面"
}
function out(obj) {
obj.innerHTML="离开"
}
----------------------------------------------------------------------------------------------------------------------------------------------------------
函数: body:
点击、松开进行图片改变:
//松开 <div id="mouse2" onmousedown="down()"onmouseup="up()">此处放图片文字等内容</div>
function up() {
var up=document.getElementById("mouse2");
up.innerHTML="<img src='image/1499480434.jpg' style='width:200px;height:200px'></img>";
}
//点下
function down() {
var down=document.getElementById("mouse2");
down.innerHTML="<img src='image/1499488740.jpg' style='width:200px;height:200px'></img>";
}
----------------------------------------------------------------------------------------------------------------------------------------------------------
函数: body:
得到与失去焦点:
function get() { <input id="get"type="text" onfocus="get()" onblur="lost()">
var get=document.getElementById("get");
alert("获得焦点")
}
function lost() {
var get=document.getElementById("lost");
alert("失去焦点")
}
----------------------------------------------------------------------------------------------------------------------------------------------------------
函数:
创建与删除节点:
// <!--创建新节点-->
function create() {
var newh=document.getElementById("add");
var h2=document.createElement("h2");
h2.innerHTML="新创的节点"
newh.appendChild(h2);
}
//<!--删除节点-->
function delecte() {
var father=document.getElementById("select");
var child=document.getElementById("child");
father.removeChild(child);
}
body:
<div id="add">
<input type="button" value="创建" onclick="create()">
<h1>旧的节点</h1>
<br>
</div>
<div id="select">
<input type="button" value="删除" onclick="delecte()">
<h1 id="child">老的节点</h1>
<br>
</div>
----------------------------------------------------------------------------------------------------------------------------------------------------------
函数: body:
打开、关闭窗口:
//打开 <input type="button" value="打开" onclick="open()"/>
<input type="button" value="关闭" onclick="close()"/>
function open() {
window.open();
}
//关闭
function close() {
window.close();
}
----------------------------------------------------------------------------------------------------------------------------------------------------------
函数:
1.从输出框中得到value并在地址栏中将其输出
2.从输出栏中得到Value并通过浏览器搜索内容
function username() {
var username=document.getElementById("username").value;
location.href="http://www.baidu.com?username="+username;
}
function sousuo() {
var username=document.getElementById("sousuo").value;
location.href="http://前后两边为随意地址只需将value所对应值修改即可;
}
body:
用户名:<input type="text" id="username"/>
<input type="button" onclick="username()">
搜索: <input type="text" id="soushuo">
<input type="button" onclick="suosuo()">
----------------------------------------------------------------------------------------------------------------------------------------------------------
函数:
历史history,前进,后退,跳到某一个历史记录站点
function back(){
//返回
window.history.back();
}
//前进
function forward(){
window.history.forward();
}
//进入某个历史站点
function go(){
window.history.forward();
} '
body:
input type="button" onclick="back()" value="后退">
<input type="button" onclick="forward()" value="前进">
<input type="button" onclick="go()" value="go">
- js(三)
- JS(三)
- js之require.js三
- JS三级联菜单
- js入门(三)
- js小记三点
- js入门教程三
- js基础【三】
- javascript js 入门三
- 三,客户端js
- js 使用三
- 三种JS对话框
- js时间倒计时(三)
- JS继承三
- 三.基本概念[js笔记]
- 常用js效果(三)
- JS自学笔记(三)
- js 省市区三级联
- 井字棋
- 例4.4 保护继承的访问规则举例
- Android实现延时执行操作
- 如何在inf文件中修改pid、vid
- mysql导入大批量数据出现MySQL server has gone away的解决方法
- JS(三)
- 【微信开发】基础知识
- JSON字符串转换为Map (fastjson)
- 知识图谱与知识栈
- Holding Bin-Laden Captive!(母函数)
- 算法竞赛入门经典(第2版)笔记--第2章
- 赛码网刷题之研究生考试
- tensorflow 学习之 cifar_10 模型定义
- 【题解】Round Numbers