简单的代码错误? [英] Simple code mistake ?

查看:64
本文介绍了简单的代码错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

点击提交时不起作用。



 $(文件).ready(function(){
$ (#submit-button)。click(function(e){

var firstName = $(#first-name)。val();
var name_regex = / ^ [a-zA-Z] + $ /;
if(firstName.length == 0){
$(#p1)。text(* Field必须填充!*);
$(#first-name)。focus();
}

else if(!firstName.match(name_regex)|| firstName.length == 0) {
$(#p1)。text(请仅使用字母。);
$(#first-name)。focus();
}
});
});
< input id =submit-buttontype =submitname =submitvalue =Submit>

我尝试过:

我尝试使用/ ----- / i regex而不是/ ---- - /。
我试过使用alert而不是$(p)。text();
我已经检查了我的脚本src链接。

解决方案

(document).ready(function(){

(#submit-button)。click(function(e){

var firstName =


(#first -name)。val();
var name_regex = / ^ [a-zA-Z] +


Doesn't work when I click submit.

                $(document).ready(function(){
                $("#submit-button").click(function(e){

		        var firstName = $("#first-name").val();
                var name_regex = /^[a-zA-Z]+$/;
        if(firstName.length == 0){
			$("#p1").text("*Field must be filled!*");
			$("#first-name").focus();
		}

		else if(!firstName.match(name_regex) || firstName.length == 0 ){
			$("#p1").text("Please use alphabets only.");
			$("#first-name").focus();
		}
	});
});
<input id="submit-button" type="submit" name="submit" value="Submit">

What I have tried:

I've tried to use /-----/i regex instead of /------/. 
I've tried to use alert instead of $("p").text();
I've checked my script src link.

解决方案

(document).ready(function(){


("#submit-button").click(function(e){ var firstName =


("#first-name").val(); var name_regex = /^[a-zA-Z]+


这篇关于简单的代码错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆