Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/89.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 单击按钮时在Jquery函数中转换脚本_Javascript_Jquery - Fatal编程技术网

Javascript 单击按钮时在Jquery函数中转换脚本

Javascript 单击按钮时在Jquery函数中转换脚本,javascript,jquery,Javascript,Jquery,我试图在jquery中集成一个按钮函数,我是jquery的学习者,但我不确定如何将脚本转换成jquery 这是一个密码 <script type="text/javascript"> var _hmc = _hmc || []; _hmc.push(['app', '<application ID>']); _hmc.push(['title','Talk with us.']); (function() { var hm = document.createElement

我试图在jquery中集成一个按钮函数,我是jquery的学习者,但我不确定如何将脚本转换成jquery

这是一个密码

<script type="text/javascript">
var _hmc = _hmc || [];
_hmc.push(['app', '<application ID>']);
_hmc.push(['title','Talk with us.']);
(function() {
var hm = document.createElement('script'); hm.type = 'text/javascript';
hm.async = true;
hm.src = 'https://hipmob.s3.amazonaws.com/hipmobchat.min.js';
var b = document.getElementsByTagName('script')[0]; b.parentNode.insertBefore(hm, b);
})();
</script>

此外,如果有人想详细说明事情是如何工作的,例如什么是| |[]等

您需要执行以下操作的代码:

jQuery('.live-chat').click(function() {
    var _hmc = _hmc || [];
    _hmc.push(['app', '<application ID>']);
    _hmc.push(['title','Talk with us.']);

    var hm = document.createElement('script');
    hm.type = 'text/javascript';
    hm.async = true;
    hm.src = 'https://hipmob.s3.amazonaws.com/hipmobchat.min.js';
    var b = document.getElementsByTagName('script')[0];
    b.parentNode.insertBefore(hm, b);

    return false;
});
jQuery('.live chat')。单击(函数(){
var _hmc=_hmc | |[];
_hmc.push(['app','');
_hmc.push(['title','Talk with us.]]);
var hm=document.createElement('script');
hm.type='text/javascript';
hm.async=true;
hm.src=https://hipmob.s3.amazonaws.com/hipmobchat.min.js';
var b=document.getElementsByTagName('script')[0];
b、 parentNode.insertBefore(hm,b);
返回false;
});
关于你的问题:

  • |
    在javascript中表示或
  • []
    是创建新数组或“数组文字”的缩写
  • 这意味着行
    var hmc=hmc | |[]
    表示
    \u hmc
    等于
    \u hmc
    或新数组
  • jQuery('.live-chat').click(function() {
        var _hmc = _hmc || [];
        _hmc.push(['app', '<application ID>']);
        _hmc.push(['title','Talk with us.']);
    
        var hm = document.createElement('script');
        hm.type = 'text/javascript';
        hm.async = true;
        hm.src = 'https://hipmob.s3.amazonaws.com/hipmobchat.min.js';
        var b = document.getElementsByTagName('script')[0];
        b.parentNode.insertBefore(hm, b);
    
        return false;
    });