Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用javaScript在不同页面上显示带有自定义消息的工具提示?_Javascript_Jquery_Tooltip - Fatal编程技术网

如何使用javaScript在不同页面上显示带有自定义消息的工具提示?

如何使用javaScript在不同页面上显示带有自定义消息的工具提示?,javascript,jquery,tooltip,Javascript,Jquery,Tooltip,我有我编写的代码,我试图使用它在需要放置工具提示的不同页面上显示带有自定义消息的工具提示。你能看一下这个,帮我把它修好吗 当前代码中正在发生的事情。我已经测试过它,看看它是否通过显式声明 customMessage[0].emailOrCell() for循环的内部,该循环通过customMessage对象数组。我怎样才能让它正常工作 提前谢谢 代码如下: var customMessage = [{ emailOrCell: function (message) {

我有我编写的代码,我试图使用它在需要放置工具提示的不同页面上显示带有自定义消息的工具提示。你能看一下这个,帮我把它修好吗

当前代码中正在发生的事情。我已经测试过它,看看它是否通过显式声明

customMessage[0].emailOrCell()
for循环的内部,该循环通过customMessage对象数组。我怎样才能让它正常工作

提前谢谢

代码如下:

var customMessage = [{
    emailOrCell: function (message) {
        if (window.location == url) {
            message = "Please enter the email address or cell phone number associated with your WebsiteName account.";
        }

        return message;

    }
}, {
    forgotPassword: function (message) {
        if (window.location == url) {
            message = "If you have never previously logged in to the app or WebsiteName , your password is your ID number or your passport number.";
        }

        return message;

    }
}];

for (var i = 0; i < customMessage.length; i++) {
    var $tooltip = $("<div class='info-tip'><div class='tool-tip-pin'></div><h2 class='tool-tip-title'>Password</h2><div class='tooltip-text'>" + customMessage[0].emailOrCell() + "</div></div>");
}


$('.info-icon').mouseenter(function () {
    $($tooltip).insertAfter(".info-icon");
}).mouseout(function () {
    if ($($tooltip).is(':visible')) {
        $($tooltip).remove();
    }
});
var customMessage=[{
emailOrCell:功能(消息){
if(window.location==url){
message=“请输入与您的WebsiteName帐户关联的电子邮件地址或手机号码。”;
}
返回消息;
}
}, {
放弃密码:函数(消息){
if(window.location==url){
message=“如果您以前从未登录过应用程序或网站名,则密码为您的身份证号码或护照号码。”;
}
返回消息;
}
}];
对于(var i=0;i
只有一个对象的数组没有多大意义。可以使用普通数组代替吗

var customMessages = [
function emailOrCell(message) {
    if (window.location == url) {
        message = "Please enter the email address or cell phone number associated with your WebsiteName account.";
    }

    return message;

}, 
function forgotPassword (message) {
    if (window.location == url) {
        message = "If you have never previously logged in to the app or WebsiteName , your password is your ID number or your passport number.";
    }

    return message;

}];
现在您可以执行以下操作:

customMessages.forEach(message=>{
 alert(message(" no problem detected!"));
});

除了一些jquery声明之外,我认为您的函数没有任何问题,您不必声明$($tooltip),因为它已经是jquery元素了

var url='/test';
var customMessage=[{
emailOrCell:功能(消息){
if(window.location==url){
message=“请输入与您的MySchool帐户关联的电子邮件地址或手机号码。”;
}
返回消息;
}
}, {
放弃密码:函数(消息){
if(window.location==url){
message=“如果您以前从未登录过MySchool应用程序或网站,您的密码是您的身份证号码或护照号码。”;
}
返回消息;
}
}];
对于(var i=0;i


信息图标
为什么数组只有一个对象???这只是样本数据。我还没有包括我还需要添加的其他内容。