将表单字段与String变量进行比较

时间:2014-03-19 07:33:12

标签: javascript jsp

String password = (String)session.getAttribute("password");
<input type = "password" placeholder = "Type your current password"  id = "pass"  />

现在,我想将表单字段中的值与变量&#34; password&#34;进行比较。如何使用JavaScript进行此操作?

1 个答案:

答案 0 :(得分:0)

这样做

html文件

<input type = "password" placeholder = "Type your current password"  id = "pass"  />

的script.js

var password="<%session.getAttribute("password");%>";
var pass=document.getElementById('pass').value; 
return pass.equals(password);