[英]Convert script in Jquery function when clicked on button
I am trying to integrate a button function in jquery, I am a learner of jquery but i am not sure how scripting can be converted into jquery 我正在尝试将按钮功能集成到jquery中,我是jquery的学习者,但我不确定如何将脚本转换为jquery
Here is a code 这是一个代码
<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>
I need to place it inside button click 我需要将其放置在按钮内
jQuery('.live-chat').click(function()
{
});
Also if anyone would like to elaborate how things work eg what is || 另外,如果有人想详细说明事物是如何工作的,例如||是什么。 [] etc
[]等
The code you would need to do what you want is the following: 您所需要做的代码如下:
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;
});
As for your questions: 至于您的问题:
||
means OR in javascript []
is shorthand for creating a new array, or an 'array literal' []
是创建新数组或“数组文字”的简写 var _hmc = _hmc || [];
var _hmc = _hmc || [];
var _hmc = _hmc || [];
means _hmc
equals _hmc
OR a new array _hmc
等于_hmc
或一个新数组
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.