【问题标题】:Submit.click JQuery event not workingSubmit.click JQuery 事件不起作用
【发布时间】:2018-05-25 09:31:46
【问题描述】:

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

      $('#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'
  });

});

我是初级开发者,如果犯了一些初学者的错误,或者类似的事情,我提前道歉,我还在开发阶段:)

提前谢谢你。

干杯。

【问题讨论】:

  • 你的缩进太可怕了。看来您必须将打开聊天框的代码放入模态关闭回调中。
  • 我还需要学习一两点关于缩进的知识,但这并不是我没有尝试 :) 可以,说我不知道​​如何进行模态关闭回调,我之前尝试过执行 $('#myModal').dialog("close") 函数,但它没有按应有的方式工作。

标签: javascript jquery click form-submit submit-button


【解决方案1】:

通过查看您的代码,我可以知道您想在“chatConfig”准备好后立即点击“创建”功能。

由于您无法打开聊天窗口,因此您假设点击事件未触发,但事实并非如此。 我认为您错过了触发您的网络聊天插件的“创建”功能。

既然,你想在按钮点击时触发它。

将你的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'
        });
    });    
});

【讨论】:

  • 谢谢辛格先生,您解决了我的问题,但现在我必须想办法在聊天弹出之前关闭提交时的模态表单。有什么想法:)?
  • 在调用 create 函数之前调用 close modal 函数。
  • 我想通了,最后再次感谢你,你帮了很多忙。
【解决方案2】:

试试这个

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-05-01
    • 1970-01-01
    • 2018-10-21
    • 2016-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多