Submit.click JQuery 活动无效

Submit.click JQuery event not working

我尝试搜索并使用您已在此处发布的一些技巧,但 none 有效。我用我的创造性思维和想法撞墙出了什么问题。我有一个打开的模态表单,我希望在单击提交按钮后能够隐藏模态,收集字段值并打开聊天界面。这是代码:

      $('#confirmation-button').click(function(){


      let firstName = $('#first-name').val();
      let lastName = $('#last-name').val();
      let firstName = $('#email').val();
      let firstName = $('#registration-number').val();


    let chatConfig = {
  "webchatAppUrl": "https://apps.mypurecloud.ie/webchat",
  "webchatServiceUrl": "https://realtime.mypurecloud.ie:443",
  "orgId": "8410",
  "orgName": "fjellinjenas",
  "queueName": "Chat",
  "logLevel": "DEBUG",
  "locale": "",
  "data": {
    "firstName": firstName,
    "lastName": lastName,
    "addressStreet": "",
    "addressCity": "",
    "addressPostalCode": "",
    "addressState": "",
    "phoneNumber": ""
  },
  "companyLogo": {
    "width": 600,
    "height": 149,
    "url": "http://i65.tinypic.com/2hr1ytg.jpg"
  },
  "companyLogoSmall": {
    "width": 25,
    "height": 25,
    "url": "http://i68.tinypic.com/2m3gto6.jpg"
  },
  "agentAvatar": {
    "width": 462,
    "height": 462,
    "url": "http://i67.tinypic.com/1eqted.png"
  },
  "welcomeMessage": "Du snakker med kundebehandler.",
  "cssClass": "webchat-frame",
  "css": {
    "width": "100%",
    "height": "100%",
    "display": "block",
    "left": "90%",

  }
};
});

ININ.webchat.create(chatConfig, function(err, webchat) {
    if (err) {
        console.error(err);
        throw err;
    }
    webchat.renderPopup({
        width: 400,
        height: 400,
        title: 'Chat'
  });

});

我是一名初级开发人员,如果让一些初学者犯了错误或类似的错误,我提前表示歉意,我仍处于开发阶段:)

提前致谢。

干杯。

试试这个

$(document).on("click",'#confirmation-button',function(){
//Code...
});

通过查看您的代码,我可以确定您想在 'chatConfig' 准备就绪后立即点击 'create' 函数。

因为您无法打开聊天 window,您假设点击事件没有触发,但事实并非如此。 我认为您错过了触发网络聊天插件的 'create' 功能。

因为,您想在单击按钮时触发它。

将您的创建方法放在点击函数的回调中。

$('#confirmation-button').click(function(){


    let firstName = $('#first-name').val();
    let lastName = $('#last-name').val();
    let firstName = $('#email').val();
    let firstName = $('#registration-number').val();


    let chatConfig = {
        "webchatAppUrl": "https://apps.mypurecloud.ie/webchat",
        "webchatServiceUrl": "https://realtime.mypurecloud.ie:443",
        "orgId": "8410",
        "orgName": "fjellinjenas",
        "queueName": "Chat",
        "logLevel": "DEBUG",
        "locale": "",
        "data": {
            "firstName": firstName,
            "lastName": lastName,
            "addressStreet": "",
            "addressCity": "",
            "addressPostalCode": "",
            "addressState": "",
            "phoneNumber": ""
        },

        "companyLogo": {
            "width": 600,
            "height": 149,
            "url": "http://i65.tinypic.com/2hr1ytg.jpg"
        },

        "companyLogoSmall": {
            "width": 25,
            "height": 25,
            "url": "http://i68.tinypic.com/2m3gto6.jpg"
        },
        "agentAvatar": {
            "width": 462,
            "height": 462,
            "url": "http://i67.tinypic.com/1eqted.png"
        },
        "welcomeMessage": "Du snakker med kundebehandler.",
        "cssClass": "webchat-frame",
        "css": {
            "width": "100%",
            "height": "100%",
            "display": "block",
            "left": "90%",
        }
    };

    ININ.webchat.create(chatConfig, function(err, webchat) {
        if (err) {
            console.error(err);
            throw err;
        }
        webchat.renderPopup({
            width: 400,
            height: 400,
            title: 'Chat'
        });
    });    
});