当用户在提示框中输入 IP 地址时,如何将 IP 地址存储到变量中。?
how to Store IP Address to Variable when user enter IP Address in prompt box.?
我是 phoneGap 的新手,我在我的代码中使用 navigator.notification.prompt。我想在提示框中添加 IP 地址 (192.168.1.201),添加的 IP 地址应保存到新变量中,并检查该变量是否为空。这是我的代码:
function config()
{
var ret =navigator.notification.prompt("Server Address : ",click me,"Server IP",["Ok","Cancel"],"");
if (ret =='')
{
navigator.notification.alert("Plz enter the correct Ip Address");
}
else
{
navigator.notification.alert("Ip address is saved for your mobile"
localStorage.setItem("ipAddress",ret);
}
}
function clickme()
{
navigator.notification.alert("Ip address is saved for your mobile", null, "Server IP", "OK");
}
但我无法将输入的 IP 地址保存到变量 return 并检查该变量是否为空。请帮我解决这个问题
您应该按以下方式使用提示...
function config() {
navigator.notification.prompt(
'Server Address : ', // message
onPrompt, // callback to invoke
'Server IP', // title
['Ok','cancel'] // buttonLabels
);
}
function onPrompt(results) {
if (results.input1 =='')
{
navigator.notification.alert("Plz enter the correct Ip Address");
}
else
{
navigator.notification.alert("Ip address is saved for your mobile");
localStorage.setItem("ipAddress",results.input1);
}
}
如果你想获取 ip 地址使用
function getIp(){
localStorage.getItem("ipAddress");
}
经过验证的完整答案
function config() {
navigator.notification.prompt(
'Server Address : ', // message
onPrompt, // callback to invoke
'Server IP', // title
['Ok','cancel'] // buttonLabels
);
}
function onPrompt(results) {
if (/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(results.input1))
{
navigator.notification.alert("Plz enter the valid Ip Address");
}
else
{
navigator.notification.alert("Ip address is saved for your mobile");
localStorage.setItem("ipAddress",results.input1);
}
}
我是 phoneGap 的新手,我在我的代码中使用 navigator.notification.prompt。我想在提示框中添加 IP 地址 (192.168.1.201),添加的 IP 地址应保存到新变量中,并检查该变量是否为空。这是我的代码:
function config()
{
var ret =navigator.notification.prompt("Server Address : ",click me,"Server IP",["Ok","Cancel"],"");
if (ret =='')
{
navigator.notification.alert("Plz enter the correct Ip Address");
}
else
{
navigator.notification.alert("Ip address is saved for your mobile"
localStorage.setItem("ipAddress",ret);
}
}
function clickme()
{
navigator.notification.alert("Ip address is saved for your mobile", null, "Server IP", "OK");
}
但我无法将输入的 IP 地址保存到变量 return 并检查该变量是否为空。请帮我解决这个问题
您应该按以下方式使用提示...
function config() {
navigator.notification.prompt(
'Server Address : ', // message
onPrompt, // callback to invoke
'Server IP', // title
['Ok','cancel'] // buttonLabels
);
}
function onPrompt(results) {
if (results.input1 =='')
{
navigator.notification.alert("Plz enter the correct Ip Address");
}
else
{
navigator.notification.alert("Ip address is saved for your mobile");
localStorage.setItem("ipAddress",results.input1);
}
}
如果你想获取 ip 地址使用
function getIp(){
localStorage.getItem("ipAddress");
}
经过验证的完整答案
function config() {
navigator.notification.prompt(
'Server Address : ', // message
onPrompt, // callback to invoke
'Server IP', // title
['Ok','cancel'] // buttonLabels
);
}
function onPrompt(results) {
if (/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(results.input1))
{
navigator.notification.alert("Plz enter the valid Ip Address");
}
else
{
navigator.notification.alert("Ip address is saved for your mobile");
localStorage.setItem("ipAddress",results.input1);
}
}