例:

<body>
<form>我的生日是哪一年?
<input type="text" value="" id="t1" name="t1" />
<input type="submit" onclick="checkName()" id="t2" name="t2" value="检查答案" />
</form>
<script language="javascript">
function Space(s){ /* 这里是删去空格,如果输入了字符串
while((s.length>0)&&(s.charAt(0)==' ')) 并且第0位是空格,那么重新截取1-最后.
s = s.substring(1, s.length); while循环直到不是空格的那位数,尾巴
while((s.length>0)&&(s.charAt(s.length-1)==' ')) 一样.*/
s = m.substring(0, s.length-1);
return s;
}
function checkName()
{
var a = document.getElementById("t1");
a.value=Space(a.value)
if(a.value.length == )
{
alert("不能为空");
}
else if(a.value==)
{
alert("正确");
}
else
{
alert("错误");
}
}
</script>
</body>

这样看起来很麻烦,我们可以通过操作属性来判断.

通过ID获取值,var a = document.getElementById("id");

a.setAttribute("属性名","属性值"); 设置一个属性,添加或更改都可以:disabled

a.getAttribute("属性名");获取属性的值

a.removeAttribute("属性名");移除一个属性

<body>

 <input type="text" answer="" value="" id="t1"  />

<input type="button" onclick="check()" value="检查答案" />

<script language="javascript">

function check()
{
var a=document.getElementById("t1");
var a1=a.value;
var a2=a.getAttribute("answer");
if(a1==a2)
{
alert("答对了!");
}
else
{
alert("再想想!");
}
}
</script>
</body>

在标签里面添一条属性, answer="1989" 可以自己命名,然后通过js获取内容用getAttribute("answer")来对比输入的内容.

我们也可以用removeAttribute来移除一个标签属性,如果移除一个关键属性就可以实现一个功能,如

<body>
<form>
<input type="submit" id="b1" name="b1" value="同意(9)" disabled="disabled" />
</form>
<script language="javascript"> var n=;
var a= document.getElementById("b1");
function bian()
{
n--;
if(n==)
{
a.removeAttribute("disabled");
a.value="同意";
return;
}
else
{
a.value= "同意("+n+")";
window.setTimeout("bian()",); //设置时间,("函数","执行间隔(毫秒)")
}
}
window.setTimeout("bian()",);
</script>
</body>


我们也可以用setAttribute来添加一个标签属性,如果移除一个关键属性就可以实现一个功能

setAttribute()里面 ("加入标签名","标签的属性值")

_________________________________________传说中的分割线___________________________________________

例子:换窗口的背图片,每隔三秒换一次,循环不止;点上一张、下一张可以切换,这时停止了自动转换。

<style type="text/css">
.pages
{
border:1px solid gray;
padding:15px 15px 15px 15px;
position:fixed;
top:200px;
text-align:center;
color:white;
background-color:#C3C;
font-weight:bold; }
#p1
{
left:10px;
}
#p2
{
right:10px;
}
</style>
</head>
<body style=" background-image:url(banner4.jpg)">
<iframe id="ff" src="preload.html" width="" height="" frameborder=""></iframe>
<div class="pages" id="p1" onclick="dodo(-1)">前一张</div>
<div class="pages" id="p2" onclick="dodo(1)">后一张</div>
</body>
<script language="javascript">
var jpg =new Array();
jpg[]="url(1.jpg)";
jpg[]="url(2.jpg)";
jpg[]="url(3.jpg)";
jpg[]="url(4.jpg)"; var xb=;
var n=;
function huan()
{
xb++;
if(xb == jpg.length)
{
xb=;
}
document.body.style.backgroundImage=jpg[xb];
if(n==)
{
var id = window.setTimeout("huan()",);
} }
function dodo(m)
{
n=;
xb = xb+m;
if(xb < )
{
xb = jpg.length-;
}
else if(xb >= jpg.length)
{
xb = ;
}
document.body.style.backgroundImage=jpg[xb];
}
window.setTimeout("huan()",);
</script>

_________________________________________传说中的分割线___________________________________________

<style type="text/css">
#main
{
width:200px;
background-color:#CCF;
}
.topic
{
font-weight:bold;
text-align:center;
background-color:#C39;
color:white;
font-size:14px;
padding:5px 0px 5px 0px;
margin-top:1px; }
.list
{
border:1px solid navy;
height:200px;
background-color:#CFF;
display:none;
}
</style>
</head>
<body> <div id="main">
<div class="topic" onclick="dodo('l1')">工作计划管理</div>
<div class="list" id="l1"> </div>
<div class="topic" onclick="dodo('l2')">个人资料管理</div>
<div class="list" id="l2"></div>
<div class="topic" onclick="dodo('l3')">部门外联管理</div>
<div class="list" id="l3"></div>
<div class="topic" onclick="dodo('l4')">系统设置</div>
<div class="list" id="l4"></div>
</div>
</body>
<script language="javascript">
function dodo(listid)
{ var dd = document.getElementById(listid);
if(dd.style.display != "block")
{
dd.style.display="block";
}
else
{
dd.style.display="none";
}
}
</script>

同一时间只允许打开一个

function dodo(listid)
{
var dd = document.getElementById(listid);
var ll = document.getElementsByClassName("list");
for(var i=;i<ll.length;i++)
{
ll[i].style.display="none";
} dd.style.display="block"; }

JS应用,表单上的一些东西的更多相关文章

  1. 使用jquery.form.js提交表单上传文件

    方法: 1.formSerilize()  用于序列化表单中的数据,并将其自动整理成适合AJAX异步请求的URL地址格式. 2.clearForm()   清除表单中所有输入值的内容. 3.restF ...

  2. 巨蟒python全栈开发django11:ajax&&form表单上传文件contentType

    回顾: 什么是异步? 可以开出一个线程,我发出请求,不用等待返回,可以做其他事情. 什么是同步? 同步就是,我发送出了一个请求,需要等待返回给我信息,我才可以操作其他事情. 局部刷新是什么? 通过jq ...

  3. [转]html5表单上传控件Files API

    表单上传控件:<input type="file" />(IE9及以下不支持下面这些功能,其它浏览器最新版本均已支持.) 1.允许上传文件数量 允许选择多个文件:< ...

  4. js验证表单大全

    js验证表单大全 1. 长度限制 <script> function test() { if(document.a.b.value.length>50) { alert(" ...

  5. JS 更改表单的提交时间和Input file的样式

    JS转换时间 function renderTime(data) { var da = eval('new ' + data.replace('/', '', 'g').replace('/', '' ...

  6. 文件的上传(表单上传和ajax文件异步上传)

    项目中用户上传总是少不了的,下面就主要的列举一下表单上传和ajax上传!注意: context.Request.Files不适合对大文件进行操作,下面列举的主要对于小文件上传的处理! 资源下载: 一. ...

  7. 普通文件的上传(表单上传和ajax文件异步上传)

    一.表单上传: html客户端部分: <form action="upload.ashx" method="post" enctype="mul ...

  8. js动态控制表单表格

    js动态控制表单表格,这里操作只讲,添加一行,删除一行,删除某一行某一列. 直接放代码: <!DOCTYPE html> <html> <head> <met ...

  9. Vue.js:表单

    ylbtech-Vue.js:表单 1.返回顶部 1. Vue.js 表单 这节我们为大家介绍 Vue.js 表单上的应用. 你可以用 v-model 指令在表单控件元素上创建双向数据绑定. v-mo ...

随机推荐

  1. TCP学习之一:TCP网络编程概念

    参考学习张子阳大神的博客:http://www.cnblogs.com/JimmyZhang/category/101698.html 一.TCP 面向连接的(UDP是无连接的) 全双工,建立连接之后 ...

  2. Eclipse 中文的设置

    步骤如下:一.下载:在Eclipse官网下载相应版本的中文包. 二.中文包安装:1.解压中文语言包中的两个文件夹至Eclipse文件夹的dropins文件夹中.(目录不要放错)2.安装:方法一:使用命 ...

  3. html5 Websockets development guidance

    1. WebSockets -- full-duplex communication The main HTML5 pillars include Markup, CSS3, and JavaScri ...

  4. Mysql字符转义

    在字符串中,某些序列具有特殊含义.这些序列均用反斜线('\')开始,即所谓的转义字符.MySQL识别下面的转义序列: \0 ASCII 0(NUL)字符. \' 单引号('''). \" 双 ...

  5. 基于Spring AOP的JDK动态代理和CGLIB代理

    一.AOP的概念  在软件业,AOP为Aspect Oriented Programming的缩写,意为:面向切面编程,通过预编译方式和运行期动态代理实现程序功能的统一维护的一种技术.AOP是OOP的 ...

  6. Struts2第一个入门案例

      一.如何获取Struts2,以及Struts2资源包的目录结构的了解    Struts的官方地址为http://struts.apache.org 在他的主页当中,我们可以通过左侧的Apache ...

  7. C++ 与OpenCV 学习笔记

    联合体:当多个数据需要共享内存或者多个数据每次只取其一时,可以利用联合体(union) 1. 联合体是一种结构: 2. 他的所有成员相对于基地址的偏移量均为0: 3. 此结构空间要大到足够容纳最&qu ...

  8. java中File类的getPath(),getAbsolutePath(),getCanonicalPath()区别

    File file = new File(".\\test.txt"); System.out.println(file.getPath()); System.out.printl ...

  9. docker 初探之简单安装 ----Windows10

    报错一 $ docker run hello-world Unable to find image 'hello-world:latest' locally Pulling repository do ...

  10. rabbitmq

    send端 import pika credentials = pika.PlainCredentials(') connection = pika.BlockingConnection(pika.C ...