import?java.awt.event.ActionEvent;
創(chuàng)新互聯(lián)主營新和網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營網(wǎng)站建設(shè)方案,成都app軟件開發(fā),新和h5成都小程序開發(fā)搭建,新和網(wǎng)站營銷推廣歡迎新和等地區(qū)企業(yè)咨詢
import?java.awt.event.ActionListener;
import?javax.swing.JButton;
import?javax.swing.JDialog;
import?javax.swing.JLabel;
import?javax.swing.JOptionPane;
import?javax.swing.JPanel;
import?javax.swing.JTextField;
import?javax.swing.WindowConstants;
public?class?keyPassword?extends?JDialog{
private?JLabel?jl1?=?new?JLabel("password:");
private?JLabel?jl2?=?new?JLabel("確認密碼");
private?JTextField?pwd1?=?new?JTextField(18);
private?JTextField?pwd2?=?new?JTextField(18);
private?JButton?sure?=?new?JButton("確定");
private?JPanel?jp1?=?new?JPanel();
public?keyPassword(){
setVisible(true);
setSize(300,?150);
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
jp1.add(jl1);
jp1.add(pwd1);
jp1.add(jl2);
jp1.add(pwd2);
jp1.add(sure);
sure.addActionListener(new?ActionListener()?{
@Override
public?void?actionPerformed(ActionEvent?arg0)?{
String?str?=?pwd1.getText();
String?str2?=?pwd2.getText();
if(str.equals("")?||?str2.equals("")){
JOptionPane.showMessageDialog(null,?"不能為空");
}else?if(str.equals(str2)){
JOptionPane.showMessageDialog(null,?"兩次密碼相同!");
}else{
JOptionPane.showMessageDialog(null,?"兩次密碼不相同!");
}
}
});
add(jp1);
}
public?static?void?main(String[]?args)?{
new?keyPassword();
}
}
最新版本:有什么問題可以聯(lián)系我,
import?java.awt.event.ActionEvent;
import?java.awt.event.ActionListener;
import?javax.swing.JButton;
import?javax.swing.JDialog;
import?javax.swing.JLabel;
import?javax.swing.JOptionPane;
import?javax.swing.JPanel;
import?javax.swing.JPasswordField;
import?javax.swing.JTextField;
import?javax.swing.WindowConstants;
public?class?keyPassword?extends?JDialog{
private?JLabel?jl1?=?new?JLabel("password:");
private?JLabel?jl2?=?new?JLabel("確認密碼");
private?JPasswordField?jpf?=?new?JPasswordField(18);
private?JPasswordField?jpf2?=?new?JPasswordField(18);
private?JButton?sure?=?new?JButton("確定");
private?JPanel?jp1?=?new?JPanel();
public?keyPassword(){
setVisible(true);
setSize(300,?150);
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
jp1.add(jl1);
jp1.add(jpf);
jp1.add(jl2);
jp1.add(jpf2);
jp1.add(sure);
sure.addActionListener(new?ActionListener()?{
@Override
public?void?actionPerformed(ActionEvent?arg0)?{
char[]?str_?=?jpf.getPassword();
String?str=String.copyValueOf(str_);
char[]?str2_?=?jpf2.getPassword();
String?str2?=String.copyValueOf(str2_);
if(str.equals("")?||?str2.equals("")){
JOptionPane.showMessageDialog(null,?"不能為空");
}else?if(str.equals(str2)){
JOptionPane.showMessageDialog(null,?"兩次密碼相同!");
}else{
JOptionPane.showMessageDialog(null,?"兩次密碼不相同!");
}
}
});
add(jp1);
}
public?static?void?main(String[]?args)?{
new?keyPassword();
}
}
只要用JavaScript判斷密碼輸入和密碼確認輸入時候一致即可。
table
tr
td valign="middle"div align="right"密碼:/div/td
tddiv align="left"
input type="password" name="userpassword" id="userpassword" /span id="error_userpassword"/span/div/td
/tr
tr
td valign="middle"div align="right"密碼確認:/div/td
tddiv align="left"
input type="password" name="userpassword_enter" id="userpassword_enter" /span id="error_userpassword_enter"/span/div/td
/tr
/table
script language="javascript1.2"
function vertify_userpassword(){
if (document.getElementById("userpassword").value==""){
document.getElementById("error_userpassword").innerText="請輸入密碼!";return false;}
else
{document.getElementById("error_userpassword").innerText="";return true}
}
/script
jsp中判斷兩次輸入的密碼是否相同的方法是通過js實現(xiàn)的。\x0d\x0a在兩個文本框里添加onchange事件,在文本框的內(nèi)容一發(fā)生變化時就觸發(fā)該事件,而判斷就寫在這個事件之內(nèi)就可以了。\x0d\x0a\x0d\x0a \x0d\x0afunction check()\x0d\x0a{\x0d\x0a\x0d\x0aif (document.form1.username.value==""){\x0d\x0aalert("請輸入登錄賬號!");\x0d\x0areturn false;\x0d\x0a}\x0d\x0aif (document.form1.passwords.value==""){\x0d\x0aalert("請輸入登錄密碼!");\x0d\x0areturn false;\x0d\x0a}\x0d\x0aif (document.form1.password.value==""){\x0d\x0aalert("請輸入重復(fù)密碼!");\x0d\x0areturn false;\x0d\x0a}\x0d\x0aif (document.form1.password.value!=document.form1.passwords.value){\x0d\x0aalert("對不起!重復(fù)密碼不等于登錄密碼");\x0d\x0areturn false;\x0d\x0a}\x0d\x0a\x0d\x0areturn true; \x0d\x0a\x0d\x0a}\x0d\x0a \x0d\x0a\x0d\x0a