当前位置:网站首页>JS–比想象中简单
JS–比想象中简单
2022-08-09 21:43:00 【全栈程序员站长】
大家好,又见面了,我是你们的朋友全栈君。
刚看完JavaScript视频的时候,感觉一点印象都没有,而且大部分效果自己都做不出来。现在看了一点SSH的视频,发现JS其实跟我们其他语言编写的代码很相似,先从最简单的开始,不断地积累就学会了。
比如说登录界面验证表单是否为空
首先在表单中添加onsubmit方法
<span style="font-family:KaiTi_GB2312;font-size:18px;"><form id="registerForm" οnsubmit=" checkForm();">
</form></span>对应的在JS中编写相应的checkForm()方法
<span style="font-family:KaiTi_GB2312;font-size:18px;"><script> //校验表单内容是否为空
function checkForm(){
//校验用户名
//获得用户名文本框的值
var username=document.getElementById("username").value;
if(username == null || username == ''){
alert("用户名不能为空!");
return false;
}
//校验密码
//获得密码框的值
var password = document.getElementById("password").value;
if(password == null || password ==''){
alert("密码不能为空!");
return false;
}
}
</script></span>从上面一段代码可以看出,跟我们平时写的VB,C#多么相似,只是在获得文本框的值的时候是通过DOM方法来取的,document.getElementById(“username”).value,当时就是因为好多类似于document.getElementById()这样的东西,把自己整蒙了,所以现在还是要一点一点还回来的。
上面是简单的表单是否为空的验证,下面就是验证邮箱格式是否正确的方法,其实也很简单,运用正则表达式就可以了
<span style="font-family:KaiTi_GB2312;font-size:18px;"> //校验邮箱
var email = document.getElementById("email").value;
var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
if(filter.test(email)){
return true;
}else{
alert("邮箱格式不正确!");
return false;
}</span>这样的JavaScript代码还是很简单的吧,先从简单的开始,这样就能相信自己能学会。
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/105730.html原文链接:https://javaforall.cn
边栏推荐
- Tensorflow中placeholder函数的用法
- Endpoint mode for NetCore routing
- 【泛型编程】模板全详解
- The kvm virtual machine cannot be started, NOT available, and the PV is larger than the partition
- [Generic Programming] Full Detailed Explanation of Templates
- 【双链表增删查改接口的实现】
- 蔚来杯2022牛客暑期多校训练营7 CFGJ
- SQLi-LABS Page-2 (Adv Injections)
- Tensorflow模型整体构建流程
- abstract class or interface
猜你喜欢

Pagoda measurement - building LightPicture open source map bed system
Quotefancy ,提供鼓舞人心语录的壁纸网站 - 倾城之链

AI识万物:从0搭建和部署手语识别系统

hdu 1503 Advanced Fruits(最长公共子序列的应用)

万字总结:分布式系统的38个知识点

角度和弧度的相互换算

AI+医疗:使用神经网络进行医学影像识别分析

浅谈Numpy中的shape、reshape函数的区别
6 rules to sanitize your code

STC8H Development (15): GPIO Drives Ci24R1 Wireless Module
随机推荐
Leetcode 93 复原IP地址
Sudoku | Backtrack-7
knn到底咋回事?
埃氏筛选法:统计素数个数
技术分享 | 接口自动化测试如何处理 Header cookie
单元测试
AI识万物:从0搭建和部署手语识别系统
Tensorflow模型整体构建流程
Pagoda measurement - building LightPicture open source map bed system
编程时请选择正确的输入法,严格区分中英文
random.normal() and random.truncated_normal() in TF
Interpretation of the paper (DropEdge) "DropEdge: Towards Deep Graph Convolutional Networks on Node Classification"
unit test
windos安装Mysql8.0,及解决重新登录异常问题 ERROR 1045 (28000)
Use zeros(), ones(), fill() methods to generate data in TF
Use convert_to_tensor in Tensorflow to specify the type of data
必看设计干货|易知微设计师是怎么做标准可视化设计服务的?
【测试】语句覆盖,判定覆盖,条件覆盖,路径覆盖
自监督学习 —— MoCo v2
json事例