您的位置:首页 > Web前端 > JavaScript

书店看不要钱的JS笔记

2008-08-22 22:17 225 查看
Cookie:

创建:

document.cookie = "name=value" ->常用编码 name=escape(value)

读取:

document.cookie ->整个字符串 name=ABC;pwd=123

可用string结束截取

删除cookie 设过期时间,但不会马上删除,最好复写一个无用值。

设过期时间:

document.cookie = "name=value;expires=date"

var now = new Date();

now.setDate(now.getDate()+1); //1天

var cookies = "name=" + escape("LS") + ";expires=" + now.toGMTString(); ->可加安全 secure

document.cookie = cookies;

表单:

<form name="myForm" onsubmit="return checkForm();"> ->返回true, false false阻止提交

reset前提示

<form onreset = "return ifReset();"> -> 返回true/false false阻止reset

function ifreset() {

return window.confirm("确定吗?"));

}

不用按钮,用document.myForm.submit()提交表单

表单元素:

input tyupe= text/password/radio/checkbox/file/button/submit/hidden/reset

input type = "button" => <button type="button"> (submit/reset)[未验证]

<textarea></textarea>多行

<select name="xx">

<option value="yy">选项名</option>

</select>

<fieldset></fieldset> 元素分组(产生方框) 视觉效果各浏览器不同

<legend>描述</legend>

<input type="text" onmouseover="this.select()" onfocus="clearText();" />

改进为仅默认值才清除

<input onmouseover="clearText(this);" />

function clearText(textbox){

textbox.focus();

if (textbox.value==textbox.defaultValue)

textbox.value = "";

}

改变多行文本框大小:

<input type="button" value="+/-" onclick="resize(big)/resize(small);" />

function resize(type)

{

if (big) document.myForm.content.rows += 5;

if (small) rows-= 5;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: