我用JavaScript编写了一个电话号码保护程序。一切正常,但是当我在搜索框中搜索姓名或电话号码时,没有显示结果:
function contact() {
var nam1=prompt("Please enter the name");
var num1=prompt("please enter the phone number");
}
contact();
function search() {
var searc= prompt("Please enter the name of your contact or phone number");
}
search();
//search box
if ( searc == nam1 ) {
alert("The phone Number is , " + num1);
}
if ( searc == num1 ) {
alert("The Contact Name is , " + nam1);
}
最佳答案
这里的问题是变量范围。
尝试这个:
var nam1;
var num1;
var searc;
function contact() {
nam1 = prompt("Please enter the name");
num1 = prompt("please enter the phone number");
}
contact();
function search() {
searc = prompt("Please enter the name of your contact or phone number");
}
search();
//search box
if ( searc == nam1 ) {
alert("The phone Number is , " + num1);
}
if ( searc == num1 ) {
alert("The Contact Name is , " + nam1);
}
关于javascript - 联系人保存结果未显示在Javascript中,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16351890/