2016-10-17 44 views
0

enter image description here如何使用字符串控制

在此第一影像放功能,我想声明一个变量,将被用于制作条件字符串,如果用户名是输入如果字符串有5个号码是将标签为EmployeeID,如果字符串有10个数字,它将被标记为studentID。

enter image description here

所以,在我创建一个应用的用户界面,员工和学生将然后评估。

回答

0

我不能推断代码语言,但我会写下一个函数,因为它是一个jQuery。

var Id = "" , type = ""; 
if($("#Userid").val().length = 5) 
{ 
    Id = $("#Userid").val(); 
    type = "employee"; 
} 
elseif($("#Userid").val().length = 10) 
{ 
    Id = $("#Userid").val(); 
    type = "student"; 
} 
else 
{ 
    alert("Invalid ID"); 
} 

希望这是帮助!现在您可以检查type变量来决定当前登录用户的类型。