html和js

1.<input type="button" value="Hello world!">

2.<button type="button">click me</button>

以上两种均可设置button

////////////////////////////

form的action属性表示表单的数据将会发送到这个地方

浏览器的method属性GET和POST两种

  • get:浏览器与表单处理服务器建立连接,然后将表单数据附加在action URL后,一次性传到服务器
  • post:浏览器与表单处理服务器建立连接,将数据按分段传输的方法传送给服务器

何时使用get或者post,参见:w3school

http://www.w3school.com.cn/tags/att_form_method.asp

////////////////////////////

<form enctype="value">

enctype 属性规定在发送到服务器之前应该如何对表单数据进行编码

当value是text/plain,表示空格转换为 "+" 加号,但不对特殊字符编码

 /////////////////////////

<input> name属性:用于标识让服务器处理

<input> size,如果是type="text" size="39"就表示可以输入39个字符

/////////////////////////

<script>
var x=document.getElementById("main");
var y=x.getElementsByTagName("p");
document.write('id 为 "main" 的 div 中的第一段文本是:' + y[0].innerHTML);
</script>
View Code

getElementById("demo")是通过id名来查找

var x = getElementsByTagName("p")是通过标签来查找

x[0].innerHTML为第一个<p>标签里面的内容

//////////////////////////

js表单验证是难点

/////////////////////////

onclick属性可以在其他元素中使用<p onclick="this.innerHTML='wocao'">hahhahha</p>

/////////////////////////

<body onload="checkCookies()">

<script>checkCooies(){}</script>

进入页面时,执行checkCookies()函数

onchange加在一个文本框,改变输入字段的内容

/////////////////////////////////////////////////////

html padding

<div style="padding:30px;30px;height:30px">看这里</div>

若加在div属性里面,表示在30x30的块周边有30px的边距

<div style="background-color:green;xxx;xxx;color:#ffffff(6个)">哈哈</div>

color:#ffffff表示“哈哈”二字为白色

//////////////////////////////////////////////////////

onmouseover="func()"

onmouseout="funca()"

func和funca()均为<script>部分里的代码

/////////////////////////////////

<input type="text">

文本框的背景颜色是obj.style.backgroundColor="yellow";

///////////////////////////////////

新增元素

var para=document.createElement("p");

var node=document.createTextNode("新段落");

para.appendChild(node);

var element=document.getElementById("div1");

element.appendChild(para);

////////////////////////////////

删除元素

parent=getElementById("id1");

child=getElementById("id2");

parent.removeChild(child);

////////////////////////////////

新建对象

1.对象的成员直接在赋值过程中新建

person = new Object();

person.lastname="guo";

person.firstname="jiale";

person.age=30;

正式定义对象

person={

firstname:"guo",

lastname:"jiale",

age:30

}

使用冒号,数字不引号,用逗号隔开

 /////////////////////////////////////

对象构造器

function person(firstname,latname,age)

{

 this.firstname=firstname;

 this.lastname=lastname;

 this.age=age;

}

myFather = new person("guo","jiale",30);

在写函数过程中生声明对象成员

/////////////////////////////////////////

添加对象的方法

function person(lastname,firstname,age){

 this.XXX=xx

this.XXX=xx

this.changeName=changeName;//一定得加

function changeName(name){xxxx}

}

外函数用于构造对象,内函数是对象的方法,红色那句得加

//////////////////////////////

按照一定样式输出一个字符串

document.write(txt.fontsize(12));

document.write(txt.fontcolor("red"));

toLowerCase()/toUpperCase()

document.write(txt.link("http://www.w3school.com.cn"));//输出的还是txt的文本,不过附上了链接

///////////////////////////////////

indexOf()与match()可用于搜索字符串

var s="hello world";

document.write(s.indexOf("hello"));

//////

var s="hello world";

document.write(s.match("hello"));

有则返回该串,无则返回null

////////////////////////////////

var d=new Date();

d.setFullYear(1993,10,2)设置时间

////////////////////////////////////////

var arr=new Array(3);

arr[0]="George";

arr[1]="Gaby";

arr[2]="Smith";

document.write(arr.join("."));

将字符串数组连接起来以"."隔开

////////////////////////////////////////

字符串 'false' 是逻辑的 true

var b6=new Boolean("false");

var b5=new Boolean("");

b5是false

null的逻辑是false

var b4=new Boolean(null);

var b7=new Boolean(NaN);

也是false

///////////////////////////////////////

1.RegExp对象test

var patt1=new RegExp("e");

document.write(patt1.test("wodesuyan"));

会按照e搜索整个串,有则返回true,无则返回false

2.var patt1=new RegExp("e");

document.write(patt1.exec("wodesuyan"));

串中有则返回e,无则返回null

3.var patt1=new RegExp("e","g")

g用于循环

4.compile

var patt1=new RegExp("e");

patt1.compile("d");

将e模式改成d模式

//////////////////////////////////

var w=window.innerWidth

var h=window.innerHeight

原文地址:https://www.cnblogs.com/gabygoole/p/4959040.html