<script type="text/javascript"> 
function register(){ 
this.check_username = function(){ 
if(document.getElementById("username").value == ""){ 
alert("用户名不能为空"); 


this.check_password = function(){ 
if(document.getElementById("password").value == ""){ 
alert("用户名不能为空"); 



new register().check_username(); //调用方法 
</script> 
上面的这种用的是方法类,大方法是register,里面定义的二个小方法,一个是对用户名的check,一个是对密码的check. 
<script type="text/javascript"> 
var register = { 
check_username:function(){ 
if(document.getElementById("username").value == ""){ 
alert("用户名不能为空"); 

}, 
check_password:function(){ 
if(document.getElementById("password").value == ""){ 
alert("用户名不能为空"); 



register.check_username(); //调用方法 
</script> 
个人觉得通过域,来对function进行管理,规划最简单明了。

相关文章:

  • 2022-12-23
  • 2021-12-06
  • 2021-12-05
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-05
  • 2022-01-04
相关资源
相似解决方案