且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在php中验证Web表单

更新时间:2023-12-03 21:01:46

1.在 my.html "head" "body" 内包含 myscript.js 文件的路径.文件.
示例:
1. Include a path to your myscript.js file inside the "head" or "body" in my.html file.
Example:
<script src="..../myscript.js" type="text/javascript"></script>


2.对于每个"input" 实例,添加事件"onclick" .
注意:您的脚本将通过"id" 查找元素,拥有唯一的ID很重要!
例子:


2.For every "input" instance add event "onclick".
NOTE : Your script is going to find an element by "id" it''s important to have a unique id!
Example :

<input type="password" id="pwd" onclick="javascript:return checkById('pwd')" />


3.I您的 myscript.js 为每个元素编写函数.
示例:


3.I your myscript.js write your function for each element.
Example:

function checkById(codeElement)
 {
	var checkInputCode = document.getElementById(codeElement);
        //get value inside the codeElement and compare it whatever you need
        if(codeElement == 'pwd')
        {
	   if(checkInputCode.value == "")
	   {
		alert("YOU ENTER NOTHING");
		return false;
           }
	   else if(checkInputCode.value == 'correct password')
	   {
                 //do something...
                 return true;
	    }
          //else if..... etc.
        }
        if(codeElement == 'surname')
        {
             ...... so on
        }
	//if nothing found return false
	return false;
}




您还可以为每个 codeElement 创建切换案例" (例如:pwd,count,ptc ...),然后针对以下内容执行 if语句正确输入.
希望我能帮上忙.




You can also create "Switch Case" for each codeElement (like : pwd,count,ptc...) and then execute if statments for correct input.
Hope i helped.