用html写input输入框?

作者&投稿:歧孙 (若有异议请与网页底部的电邮联系)
HTML页面中,如何设置一个input输入框的焦点?~

需要准备的材料分别有:电脑、浏览器、html编辑器。
1、首先,打开html编辑器,新建html文件,例如:index.html,输入问题基础代码。

2、在index.html中的标签,输入js代码:$('input').focus();。

3、浏览器运行index.html页面,此时页面一载入,这个input就是聚焦的状态。

mytxt 是你那个input 控件的ID

用javascript:
document.getElementById('mytext').value="aaaa";
用jQuery:
$("#mytxt").val("me");
这句jQuery语句的意思是给你叫mytxt的控件加value值为me。

演示图如下:

用到的是js和正则表达式代码如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">    

<html xmlns="http://www.w3.org/1999/xhtml">    

<head>    

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />    

<title>html留言表单验证</title>    

<style>    

*{margin:0px;padding:0px;}    

body{background-color:#f9f9f9;}    

.clears{ clear:both;}    

/*messages*/    

.messages{padding:15px 0;}    

.messages input,.messages select,.messages textarea{margin:0;padding:0; background:none; border:0; font-family:"Microsoft Yahei";}    

.messlist {height:30px;margin-bottom:10px;}    

.messlist label{float:left;width:100px; height:30px; font-size:14px; line-height:30px; text-align:right;padding-right:10px;}    

.messlist input{float:left;width:300px;height:28px;padding-left:5px;border:#ccc 1px solid;}    

.messlist.textareas{ height:auto;}    

.messlist textarea{float:left;width:400px; height:110px;padding:5px;border:#ccc 1px solid;}    

.messlist.yzms input{width:100px;}    

.messlist.yzms .yzmimg{ float:left;margin-left:10px;}    

.messsub{padding:0px 0 0 110px;}    

.messsub input{width:100px; height:35px; background:#ddd; font-size:14px; font-weight:bold; cursor:pointer;margin-right:5px}    

.messsub input:hover{ background:#f60;color:#fff;}    

#label0{display:none;color:#0aa770;height:28px;line-height:28px;}    

#label1{display:none;color:#0aa770;height:28px;line-height:28px;}    

#label2{display:none;color:#0aa770;height:28px;line-height:28px;}    

#label3{display:none;color:#0aa770;height:28px;line-height:28px;}    

#label4{display:none;color:#0aa770;height:28px;line-height:28px;}    

#label5{display:none;color:#0aa770;height:28px;line-height:28px;}    

#label6{display:none;color:#0aa770;height:28px;line-height:28px;}    

#label7{display:none;color:#0aa770;height:28px;line-height:28px;}    

#label8{display:none;color:#0aa770;height:48px;line-height:48px;}    

#label9{display:none;color:#0aa770;height:48px;line-height:48px;}    

#label10{display:none;color:#0aa770;height:48px;line-height:48px;}    

</style>    

</head>    

<body>    

<br>    

<div class="mail">    

<div class="send">    

<div class="sendbox">    

<form action="#" method="get" class="messages">    

<div class="messlist">    

<label>姓名</label>    

<input type="text" placeholder="姓名" id="input1" onblur="jieshou()"/>    

<div id ="label0">*你还没填写名字呢!</div>    

<div id ="label1">√正确</div>    

<div id ="label2">×错误</div>    

<div class="clears"></div>    

</div>    

<div class="messlist">    

<label>电子邮件</label>    

<input type="text" placeholder="电子邮件" id="input2" onblur="mailtext()"/>    

<div id ="label3">√正确</div>    

<div id ="label4">×邮箱地址错误</div>    

<div id ="label5">*必填</div>    

<div class="clears"></div>    

</div>    

<div class="messlist">    

<label>手机号</label>    

<input type="text" placeholder="手机号" id="input3" onblur="phonetext()"/>    

<div id ="label6">√正确</div>    

<div id ="label7">×手机号码错误</div>    

<div class="clears"></div>    

</div>    

<div class="messlist textareas">    

<label>留言内容</label>    

<textarea placeholder="说点什么吧..." id="input4" onblur="content()"></textarea>    

<div id ="label8">√</div>    

<div id ="label9">×</div>    

<div id ="label10">* 必填</div>    

<div class="clears"></div>    

</div>    

<div class="messlist yzms">    

<label>验证码</label>    

<input type="text" placeholder="验证码" id="input5" />    

<img src="../images/code.jpg" width="64" height="27" class="yzmimg" />    

<div class="clears"></div>    

</div>    

<div class="messsub">    

<input type="submit" value="提交" onclick="send()"style="background:#00a3eb;color:#fff;" />    

<input type="reset" value="重填" />    

</div>    

</form>     

<script>    

function send(){    

var name = document.getElementById("input1").value;    

var mail = document.getElementById("input2").value;    

var phone = document.getElementById("input3").value;    

var content = document.getElementById("input4").value;    

var code = document.getElementById("input5").value;    

if(name=="")    

{    

label2.style.display = 'none';    

label1.style.display = 'none';    

label0.style.display = 'block';;    

return false;    

}    

if(mail=="")    

{    

label3.style.display = 'none';    

label4.style.display = 'none';    

label5.style.display = 'block';;    

return false;    

}    

if(content=="")    

{    

label8.style.display = 'none';    

label9.style.display = 'none';    

label10.style.display = 'block'; //*必填    

return false;    

}    

if(code=="")    

{    

alert('请填写验证码!');    

return false;    

}    

else{    

alert('信息已发送到站长邮箱,感谢您的支持!');    

}    

}    

</script>    

<script>    

function jieshou(){    

var label1 = document.getElementById("label1");    

var label2 = document.getElementById("label2");    

var nametext = document.getElementById("input1").value;    

if(nametext!=""){    

label0.style.display = 'none';    

label1.style.display = 'block';    

label2.style.display = 'none';    

}    

else{    

label0.style.display = 'block';    

label1.style.display = 'none';    

label2.style.display = 'none';    

}    

}    

</script>    

<script>    

function mailtext(){    

var mailvalue = document.getElementById("input2").value;    

var mailtext = document.getElementById("input2");    

var myreg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;    

if(mailvalue!=""){ //邮箱如果非空 显示正确    

label5.style.display = 'none';    

label3.style.display = 'block';//显示正确    

label4.style.display = 'none';    

}    

else{    

label5.style.display = 'block';//显示*必填    

label3.style.display = 'none';    

label4.style.display = 'none';    

return false;    

}    

//上面为一段    

if(!myreg.test(mailvalue)){  //既而 正则表达式 验证邮箱 如果不是邮箱地址label4显示出来    

label3.style.display = 'none';    

label4.style.display = 'block'; //*邮箱地址错误    

return false;    

}    

else{    

label3.style.display = 'block';    

label5.style.display = 'none';    

label4.style.display = 'none';    

}    

//上面为一段    

}    

</script>    

<script>    

function phonetext(){    

var phonetext = document.getElementById("input3").value;    

if(!(/^1[3|4|5|7|8]\d{9}$/.test(phonetext))){    

label6.style.display = 'none';    

label7.style.display = 'block'; //*手机号码错误    

return false;    

}    

else{    

label6.style.display = 'block';    

label7.style.display = 'none';    

}    

}    

</script>    

</script>    

<script>    

function content(){    

var content = document.getElementById("input4").value;    

if(content!=""){    

label8.style.display = 'block';    

label9.style.display = 'none';    

label10.style.display = 'none'; //*必填    

return false;    

}    

else{    

label8.style.display = 'none';    

label9.style.display = 'none';    

label10.style.display = 'block';    

}    

}    

</script>    

</div>    

</div>    

</div>    


(---------满意采纳奥---------)



<input type="text" name="txt" onchange="validate(this)"/> <span id="txt_msg"></span>
<script>
function validate(e){
var msg = document.getElementById(e.name+'_msg')
if(isNaN(e.value)){
msg.innerHTML="你输入的不是数字";
msg.style.color="red";
}else{
msg.innerHTML="很棒,你输入的是数字";
msg.style.color="green";
}
}
</script>


标签<input>的class属性是干什么用的?怎么用啊?
class属性指定的样式,在css中称为“类”,可以用来修饰标签元素。1、新建html文档,在body标签中添加一个input标签,在inpu标签中添加一些文字:2、设置一个类,类的格式是“.”+“类名”,这里类名以demo为例,然后为这个类添加一些样式:3、使用class属性将之前设置的类添加到input标签上,这时input...

如何设置inpu
改变背景颜色 通过在CSS样式表中设置"#demo { background-color: red; }",可以直接将input的背景色设为红色。同时,使用JavaScript的getElementById方法和background属性,可以动态地将input的背景颜色改为粉色。只需在HTML文件中添加一个按钮,点击后调用changeBackgroundColor函数即可实现颜色的切换。

autocomplete="off" inpu属性
autocomplete 属性是 HTML5 中的新属性,在input中autocomplete属性是默认开启的。1、定义:autocomplete属性规范表单是否启用自动完成功能。自动完成允许浏览器对字段的输入,是基于之前输入过的值。2、应用范围:autocomplete适用<form>,以及<input>类型的text、search、url、telephone、email、password、datepicke...

除了textarea和inpu还有没有用户输入的
html语言里面给用户输入的标签只有两种 文本框:<input>标签 文本域:<textarea>标签

3 增加表单的隐藏域的HTML代码是 A<inputtype="submit"> B<inpu...
都不对,正确的应该是 <input type="hidden">

.plt格式的文件详解
IN; SP1; PU 0,0; PD 100,100; PU; SP0; IN;这段代码,就像一个精炼的艺术语汇,诠释了命令的韵律:初始化(IN)开启画布,选择画笔(SP1)选定了工具,移动并绘制(PU和PD)线条,最后放下画笔并结束选择(SP0),这就是图形起笔与落笔的节奏。PLT文件的魔法在于它丰富的指令集,涵盖了从...

液位数显表里的inpu是什么意思
液位数显表的的input,代表信号输入,就是测量液位传感器过来的信号。微浩科技

电脑开机屏幕显示INPU是什么?
那个 是显示器 检测有没有 输入信号用的 ,一般你拔了 接口 它就显示没有输入信号了 就会出现 not input 等 字眼。

1200 plc pid中input_per,per是什么单词
INPUT是现场仪表测量数据,经过程序标定转换成实际工程量数据。数据类型是实数。 INPU-PER是现场仪表数据直接经过模拟量通道进行测试,未进行数据标定,数据类型是WORD。可以通过PID组态直接进行数据标定,转换成实际工程量。推荐使用此方法。Setpoint:设定值,PID系统通过调解输出设备,使反馈值与设定值相等。设...

Indesign CS 巧排拼音的方法
一、在Mac机上用彩蝶中文排版工具或Indesign CS中文版打开Indd拼音版文档的步骤 首先,请安装好拼音字体ChinesePinyin.ttf;GBPinyinok.ttf;否则拼音韵母显示不出来。其次开启彩蝶中文排版工具或者IndesignCS中文版;双击注音软件生成的加了汉语拼音的OUTPU.Indd文档。一般情况下会有几次提示:正在处理文章.....

杏花岭区17242488058: html里输入框和密码框的提示文字怎么弄 -
娄冉黄师: 需要准备的材料分别有:电脑、chrome浏览器、html编辑器. 1、首先打开html编辑器,新建一个html文件,例如:index.html. 2、在index.html中的<body>标签中,输入以下html代码: <input type="text" placeholder="请输入账号" /> <input type="password" placeholder="请输入密码" /> 3、浏览器运行index.html页面,此时的输入框有了提示文字“请输入账号”,密码框有了提示文字“请输入密码”.

杏花岭区17242488058: HTML页面中,如何设置一个input输入框的焦点? -
娄冉黄师: 需要准备的材料分别有:电脑、浏览器、html编辑器. 1、首先,打开html编辑器,新建html文件,例如:index.html,输入问题基础代码. 2、在index.html中的<script>标签,输入js代码:$('input').focus();. 3、浏览器运行index.html页面,此时页面一载入,这个input就是聚焦的状态.

杏花岭区17242488058: html+js怎么实现input输入框? -
娄冉黄师: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/...

杏花岭区17242488058: 用css怎么写输入框 -
娄冉黄师: 用CSS怎么能写输入框呢,CSS只是用来写样式的.要写输入框就用HTML的<input>标签.例如: <input type="text" name="username" /> <input type="password" name="password">

杏花岭区17242488058: html 中怎样定义一个只能输入整数的<input>?( 我现在用的是php语言.) -
娄冉黄师: 只能输入数字和小数点的文本框: <input onkeyup="value=value.replace(/[^\d]/g,'')">

杏花岭区17242488058: html怎样对input样式进行样式 -
娄冉黄师: 1. 可以直接定义input{color:#ccc;border: ;}等全局属性.所有Input的文本框都会应用该样式. 2. 可以定义某种类型文本框,比如 input[type='text']{}就是所有文本框类型为text的都应用该样式. 3. 可以直接给某个input添加class,然后给指定的class进行样式渲染,比如<input type="button" class="inp-btn"/>那么就给 .inp-btn{}添加样式即可.

杏花岭区17242488058: html语言input标签用法 -
娄冉黄师: a c d e input可以做:button,reset,submit按钮 text文本框 file文件路径选择界面 password密码输入框 checkbox复选框 radio单选按钮/单选按钮组 Hidden隐藏域

杏花岭区17242488058: html中实现添加输入框怎么实现 -
娄冉黄师: 下面代码是一个例子 html <div id="org"></div> //注意:id不能写在button上,js获取不到button的id(可能是我们公司的框架的原因) <input type="button" onclick="add1();" value="添加" />script <script type="text/javascript"> function ...

杏花岭区17242488058: HTML INPUT只能输入数字 -
娄冉黄师: 1. 限制HTML的input只能输入数字代码为: <input id="amount" style="IME-MODE: disabled; WIDTH: 60px; HEIGHT: 15px" onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')" maxlength=...

杏花岭区17242488058: 创建一个html页面,使用<input>标签创建一个输入框和一个按钮.在输入框中输入数字n,点击按钮后输出 1!+2!+…+n!的结果. -
娄冉黄师: <input type="text" id="input"/> <input type="button" id="submit" /> <span id="output"></span> <script> $('#submit').click(function(){var i=parseInt()($('#input').val());//转换为数字 var html=null;for(var j=1;j<=i;j++){if(j==i){html+=j+"!";}html+=j+"!&nbsp;+"; }$('#output').html(html); }) </script>//jquery代码

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 星空见康网