900字范文,内容丰富有趣,生活中的好帮手!
900字范文 > 基于jquery的设置页面文本框 只能输入数字的实现代码【jquery】

基于jquery的设置页面文本框 只能输入数字的实现代码【jquery】

时间:2021-12-17 01:24:12

相关推荐

基于jquery的设置页面文本框 只能输入数字的实现代码【jquery】

web前端|js教程

文本框,数字

web前端-js教程

代码如下:

仿qq群聊天源码v2.1,vscode查询库地址,ubuntu无桌面,tomcat 网络堵塞,sqlite 3-6-3,数据挖掘与网络爬虫的区别,php 资产管理系统,vue单页面seo,360金融网站源码,网页设计 pdf,ecshop收货人模板lzw

$("#money").bind("propertychange",function() {

if(""!=this.value){

var str = this.value.replace(/(^\s*)|(\s*$)/g, "");

if(this.value != str )

this.value = str;

}

if( isNaN(Number(this.value)))

this.value = this.value.replace(/[\D]/,\);

});

这里使用了JQuery绑定到id为money的文本框的onpropertychange事件上。

下面的代码连小数点也屏蔽掉了

php在线教育平台源码,vscode自动补充代码c,ubuntu系统问题,修改tomcat部署路径,手sqlite,大学学校网页设计模板,wdcp 数据库密码忘记,如何查网站服务器速度,90级 九宫插件,前端 图表 框架,养眼图爬虫,php 延迟执行,黄飞seo博客,js何springboot,软件交易网站源码,金色网页模板,用药查询网页模板,shopex后台跳转,页面 表格 排序,微动力-微信公众平台管理系统,企业小程序网站源码lzw

$("#phone").bind("propertychange", function() {

if(""!=this.value){

var str = this.value.replace(/(^\s*)|(\s*$)/g, "");

if(this.value != str )

this.value = str;

}

if (this.value.indexOf(.) != -1) {

this.value = this.value.replace(/[\.]/, \);

this.focus(); }

if (isNaN(Number(this.value))) {

this.value = ($.trim(this.value)).replace(/[\D]/, \);

this.focus(); } });

最后,最好将输入法屏蔽掉。 通过css,ime-mode:disabled就可以实现。

如果很严格的话,可以再追加上禁止粘贴与拖拽。

禁止粘贴与拖拽实现方法

文本框禁止拖拽和粘贴

简单视频网站asp源码,vscode 插件的设置,ubuntu拼接双屏,不错的tomcat监控,sqlite框架有必要用吗,哪里有卖宠物蛇的爬虫店,php rsa 算法,荥阳市网络seo,下载cms网站源码下载,魔域游戏网站模板lzw

在css中实现文本框禁止拖拽和粘贴的功能

建立一个Css,如下:

.TextBox_NotDragpaste

{

ondragenter:expression(ondragenter=function(){return false;});

onpaste:expression(onpaste=function(){return false;});

}

如果还需要禁止输入中文的功能只需要多加一个语句即可。

如下:

.TextBox_NotDragpaste

{

ime-mode:disabled;

ondragenter:expression(ondragenter=function(){return false;});

onpaste:expression(onpaste=function(){return false;});

}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。