自定义js文件

2025-09-27 08:37:10

1、首先创建js文件,然后编写js内容,可以使用原生js,也可以使用jquery的方式写。 var a=document.getElementById(id).value;

var b =$(id).val();

获取节点的值使用这两种方式都是可以的,

自定义js文件

2、如果不是使用的原生js写的,那么必须引入jquery才可以生效,也就是说,第二种方式是依赖jquery的;

自定义js文件

3、function checkName(id){ var a=document.getElementById(id).value; if(a==null||a=="用户名不能为空"||a==""){  $('#ename').val('用户名不能为空');  return false; } return true;}

自定义js文件

4、简单的弹出对话框

function alertHello(id){ alert(id)}

非空验证function checkNull(id){ var a = $(id).val(); if(a==null || a==""){  return false; } return true;}

自定义js文件

1、 jQuery("#theForm").validate({ ignore: "",     rules: {         goods_class_id:{        required:true   },    goods_serial:{        maxlength:20   },   goods_name:{        required:true,     minlength:3,     maxlength:50       },  

自定义js文件

2、  goods_price:{       required:true,    number:true,    range:[0.01,1000000]    },    goods_weight:{    number:true    },   goods_volume:{    number:true    },    store_price:{       required:true,    number:true,    range:[0.01,1000000]    },   

自定义js文件

3、 goods_inventory:{       number:true,    range:[1,1000000000]    },    transport_id:{transportId:true}   },     messages: {         goods_class_id:{required:"商品分类不能为空"},   goods_serial:{maxlength:"输入字符长度不得超过20"},   goods_name:{       required: "商品名不能为空",       minlength:"商品名最少为3个字符",       maxlength:"商品名最多为50个字符"     },   goods_price:{       required:"商品原价不能为空",    number:"商品原价只能是数字格式",    range:"商品价格只能在0.01-1000000之间"    }, 

自定义js文件

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢