文本框组件实现填空效果,自动跟随中文变大.
来源:互联网 发布:淘宝用花呗付款好吗 编辑:程序博客网 时间:2024/06/03 15:38
<!DOCTYPE html>
<html>
<span style="white-space:pre"> </span><head>
<span style="white-space:pre"> </span><meta charset="UTF-8">
<span style="white-space:pre"> </span><title></title>
<span style="white-space:pre"> </span><style>
<span style="white-space:pre"> </span> input{
<span style="white-space:pre"> </span> <span style="white-space:pre"></span>outline:none;
<span style="white-space:pre"> </span> }
<span style="white-space:pre"> </span>.space{
<span style="white-space:pre"> </span> border:0px;
<span style="white-space:pre"> </span> outline:none;
<span style="white-space:pre"> </span> border-bottom: 2px;
<span style="white-space:pre"> </span> border-style: solid;
<span style="white-space:pre"> </span> border-color: #000;
<span style="white-space:pre"> </span> -webkit-appearance: none;
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>.space:focus
{
<span style="white-space:pre"> </span> <span style="white-space:pre"></span> border:0px;
<span style="white-space:pre"> </span> border-bottom: 2px;
<span style="white-space:pre"> </span> border-style: solid;
<span style="white-space:pre"> </span> border-color: red;
}
<span style="white-space:pre"> </span></style>
<span style="white-space:pre"> </span><script type="text/javascript">
window.onload=function(){<span style="white-space:pre"></span>
var nodes= document.getElementsByClassName("space");
for(var i = 0; i < nodes.length; i++){
nodes[i].onkeyup=function(){
var chinasize=0;
var maxtextsize=this.maxLength*2;
var mintextsize=4;
var re=/[^\u0000-\u00ff]/g;
chinasize=this.value.replace(re,"aa").length;
if ((chinasize>=mintextsize) && (chinasize<=maxtextsize)){
<span style="white-space:pre"> </span> //console.log("此时chinasize:"+chinasize+" mintextsize:"+mintextsize+" maxtextsize:"+maxtextsize +" maxLength:"+this.maxLength);
<span style="white-space:pre"> </span> this.size=chinasize;
}else if(chinasize>maxtextsize){
<span style="white-space:pre"> </span> this.size=maxtextsize;
}else{
<span style="white-space:pre"> </span>this.size=mintextsize;
}
}
}
};
function msgbox(){
<span style="white-space:pre"> </span>alert(document.getElementById('an1').value);
}
<span style="white-space:pre"> </span></script>
<span style="white-space:pre"> </span></head>
<span style="white-space:pre"> </span><body>
<span style="white-space:pre"> </span><input type="text" class="space" id="an1" size="4" maxLength=10 > <br>
<span style="white-space:pre"> </span><input type="text" class="space" id="an4" size="4" maxLength=20> <br><br>
<span style="white-space:pre"> </span><input type="submit" onclick="msgbox()" value="获取输入">
<span style="white-space:pre"> </span></body>
</html>
<html>
<span style="white-space:pre"> </span><head>
<span style="white-space:pre"> </span><meta charset="UTF-8">
<span style="white-space:pre"> </span><title></title>
<span style="white-space:pre"> </span><style>
<span style="white-space:pre"> </span> input{
<span style="white-space:pre"> </span> <span style="white-space:pre"></span>outline:none;
<span style="white-space:pre"> </span> }
<span style="white-space:pre"> </span>.space{
<span style="white-space:pre"> </span> border:0px;
<span style="white-space:pre"> </span> outline:none;
<span style="white-space:pre"> </span> border-bottom: 2px;
<span style="white-space:pre"> </span> border-style: solid;
<span style="white-space:pre"> </span> border-color: #000;
<span style="white-space:pre"> </span> -webkit-appearance: none;
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>.space:focus
{
<span style="white-space:pre"> </span> <span style="white-space:pre"></span> border:0px;
<span style="white-space:pre"> </span> border-bottom: 2px;
<span style="white-space:pre"> </span> border-style: solid;
<span style="white-space:pre"> </span> border-color: red;
}
<span style="white-space:pre"> </span></style>
<span style="white-space:pre"> </span><script type="text/javascript">
window.onload=function(){<span style="white-space:pre"></span>
var nodes= document.getElementsByClassName("space");
for(var i = 0; i < nodes.length; i++){
nodes[i].onkeyup=function(){
var chinasize=0;
var maxtextsize=this.maxLength*2;
var mintextsize=4;
var re=/[^\u0000-\u00ff]/g;
chinasize=this.value.replace(re,"aa").length;
if ((chinasize>=mintextsize) && (chinasize<=maxtextsize)){
<span style="white-space:pre"> </span> //console.log("此时chinasize:"+chinasize+" mintextsize:"+mintextsize+" maxtextsize:"+maxtextsize +" maxLength:"+this.maxLength);
<span style="white-space:pre"> </span> this.size=chinasize;
}else if(chinasize>maxtextsize){
<span style="white-space:pre"> </span> this.size=maxtextsize;
}else{
<span style="white-space:pre"> </span>this.size=mintextsize;
}
}
}
};
function msgbox(){
<span style="white-space:pre"> </span>alert(document.getElementById('an1').value);
}
<span style="white-space:pre"> </span></script>
<span style="white-space:pre"> </span></head>
<span style="white-space:pre"> </span><body>
<span style="white-space:pre"> </span><input type="text" class="space" id="an1" size="4" maxLength=10 > <br>
<span style="white-space:pre"> </span><input type="text" class="space" id="an4" size="4" maxLength=20> <br><br>
<span style="white-space:pre"> </span><input type="submit" onclick="msgbox()" value="获取输入">
<span style="white-space:pre"> </span></body>
</html>
0 0
- 文本框组件实现填空效果,自动跟随中文变大.
- JqueryUI AutoComplate实现文本框搜索,自动补全效果
- JavaScript实现带自动提示的文本框效果代码
- cocos2dx 跟随光线效果实现
- 实现宠物跟随移动效果
- [Android] Gallery选中变大效果的实现
- 将文本框内容变大写的几种实现方式
- Cocos2d-x 跟随光线效果实现
- 实现鼠标跟随的放大镜效果
- 动画过渡实现鼠标跟随导航效果
- 自写的文本框 输入法框跟随光标 实现方法
- 【Android开发】高级组件-自动完成文本框
- Android高级组件之自动完成文本框
- 安卓高级组件----自动完成文本框
- 跟随文本框的DIV
- 使用StateListAnimator实现Button按下变小,抬起变大效果
- 实现tableView上headerView图片下拉变大效果
- iOS下实现下拉图片变大的效果
- cmake入门教程
- 很牛的netcat
- android图文居中按钮控件
- HTML地址栏(hash)获取并转码(个人菜鸟笔记)
- php pdo链接mysql数据库
- 文本框组件实现填空效果,自动跟随中文变大.
- C++中对象或其对象指针的赋值
- 常用的正则表达式---学习笔记(一)
- ajax,php,jsp,ajax跨域调用
- 互联网开发全面进入开发直接运维的时代
- 修改searchBar两种后背景颜色
- eclipse 安装php插件及配置xampp集成环境开发php项目
- java 八大排序算法详解
- UE4中FName,Fstring,FText使用规则及相互转换