Javascript JQuery—在调用另一个函数的函数中有一个按钮
我似乎无法将onclick事件从一个常规按钮复制到一个也有一个带有onclick事件的按钮的函数 我正在使用:Javascript JQuery—在调用另一个函数的函数中有一个按钮,javascript,jquery,Javascript,Jquery,我似乎无法将onclick事件从一个常规按钮复制到一个也有一个带有onclick事件的按钮的函数 我正在使用: <input type="button" name="passw" id="passw" value="Password" onclick="DisplayPassword();"> 作为调用此函数的“我的”按钮: function DisplayPassword(){ DispWin = window.open('','toolbar=no,status=n
<input type="button" name="passw" id="passw" value="Password" onclick="DisplayPassword();">
作为调用此函数的“我的”按钮:
function DisplayPassword(){
DispWin = window.open('','toolbar=no,status=no')
message="<form name=checkPW>";
message+="<center><table cellpadding=30 border=1><tr><td><label>Password</label></td><td><input type=text name=password id=password></td></tr>";
message+="<tr><td><input type=button value=Check onclick=CheckPassword()></td><td><input type=reset value=Clear></td></tr>";
DispWin.document.write(message);
}
函数显示密码(){
DispWin=window.open(“”,'toolbar=no,status=no')
message=“”;
消息+=“密码”;
消息+=“”;
DispWin.document.write(消息);
}
其中包含一个按钮,我想调用另一个函数:
function CheckPassword(){
DispWin = window.open('','toolbar=no,status=no')
if(document.checkPW.password.value == 'yayy')
{
message="<h1><center>Correct Password!</center><h1>";
}
else
{
message="<input type=button value=Close onclick=self.close()>";
}
DispWin.document.write(message);
}
函数CheckPassword(){
DispWin=window.open(“”,'toolbar=no,status=no')
如果(document.checkPW.password.value=='yayy')
{
message=“正确密码!”;
}
其他的
{
message=“”;
}
DispWin.document.write(消息);
}
首先,您正在写入DispWin
弹出窗口的HTML无效,并且缺少
、
和
标记的结束标记
现在,要从DispWin
弹出窗口上的按钮调用JavaScript函数,需要将函数写入弹出窗口:
message+="<script>function CheckPassword(){";
message+="DispWin = window.open('','toolbar=no,status=no');";
message+="if(document.checkPW.password.value == 'yayy') {message='<h1><center>Correct Password!</center><h1>';}";
message+="else {message='<input type=button value=Close onclick=self.close()>';}";
message+="DispWin.document.write(message);}";
DispWin.document.write(message);
message+=“函数CheckPassword(){”;
message+=“DispWin=window.open(“”,'toolbar=no,status=no');”;
message+=“if(document.checkPW.password.value=='yayy'){message='Correct password!';}”;
message+=“else{message='';}”;
message+=“DispWin.document.write(message);}”;
DispWin.document.write(消息);
请记住,弹出窗口对用户来说非常烦人,可能会被某些浏览器阻止。考虑使用<代码> div <代码>弹出窗口。尝试此消息+=“”;你只是在创建一堆无效的htmlI,我想问题可能是因为checkPassword没有包含在引号中。因此,请尝试将它们与转义字符一起添加到引号中