2016-08-05 52 views
0

我有Zoplim插件(聊天功能)我希望隱藏這個,直到我的按鈕被點擊。隱藏聊天室腳本,直到按鈕單擊

所以聊天室被隱藏,直到聞測試按鈕被按下,則衣帽間顯示

腳本

<script type="text/javascript"> 
    window.$zopim || (function (d, s) { 
     var z = $zopim = function (c) { 
      z._.push(c) 
     }, $ = z.s = 
       d.createElement(s), e = d.getElementsByTagName(s)[0]; 
     z.set = function (o) { 
      z.set._.push(o) 
     }; 
     z._ = []; 
     z.set._ = []; 
     $.async = !0; 
     $.setAttribute('charset', 'utf-8'); 
     $.src = '//v2.zopim.com/?1l9izSc2QRurE71l1L7ugke4Soo38dPc'; 
     z.t = +new Date; 
     $.type = 'text/javascript'; 
     e.parentNode.insertBefore($, e) 
    })(document, 'script'); 
</script> 

我的按鈕HTML

<button id="finish-button" class="button finish m2">End test</button> 

我已嘗試

<script type="text/javascript"> 
    document.getElementById("finish-button").onclick = function() 
    {myFunction()}; 
     window.$zopim || (function (d, s) { 
      var z = $zopim = function (c) { 
       z._.push(c) 
      }, $ = z.s = 
        d.createElement(s), e = d.getElementsByTagName(s)[0]; 
      z.set = function (o) { 
       z.set._.push(o) 
      }; 
      z._ = []; 
      z.set._ = []; 
      $.async = !0; 
      $.setAttribute('charset', 'utf-8'); 
      $.src = '//v2.zopim.com/?1l9izSc2QRurE71l1L7ugke4Soo38dPc'; 
      z.t = +new Date; 
      $.type = 'text/javascript'; 
      e.parentNode.insertBefore($, e) 
     })(document, 'script'); 
</script> 
+0

這裏是'myFunction的()'的代碼? – madalinivascu

+0

https://jsfiddle.net/8j8novbp/4/ –

+0

你會得到什麼樣的錯誤?你究竟在哪裏卡住? –

回答

1

只需將您想要發生的代碼按下完成按鈕後,功能myFunction()現在。

注意當按下完成按鈕時出現錯誤,因爲執行該腳本時未在該程序中考慮到某些事物。

<button id="finish-button" class="button finish m2">End test</button> 
 

 
<script type="text/javascript"> 
 
      document.getElementById("finish-button").onclick = function() { 
 
       window.$zopim || (function (d, s) { 
 
        var z = $zopim = function (c) { 
 
         z._.push(c) 
 
        }, $ = z.s = 
 
          d.createElement(s), e = d.getElementsByTagName(s)[0]; 
 
        z.set = function (o) { 
 
         z.set._.push(o) 
 
        }; 
 
        z._ = []; 
 
        z.set._ = []; 
 
        $.async = !0; 
 
        $.setAttribute('charset', 'utf-8'); 
 
        $.src = '//v2.zopim.com/?1l9izSc2QRurE71l1L7ugke4Soo38dPc'; 
 
        z.t = +new Date; 
 
        $.type = 'text/javascript'; 
 
        e.parentNode.insertBefore($, e) 
 
       })(document, 'script'); 
 
       } 
 
     </script>

0

你有這個想法,問題是,你必須從你的,你是它assing到按鈕的功能裏面聊天執行代碼,在這種情況下,只有當你點擊,這部分代碼將被執行。檢查我的例子

https://jsfiddle.net/b7z0jnsc/

document.getElementById("finish-button").onclick = function(){ 
       window.$zopim || (function (d, s) { 
        var z = $zopim = function (c) { 
         z._.push(c) 
        }, $ = z.s = 
          d.createElement(s), e = d.getElementsByTagName(s)[0]; 
        z.set = function (o) { 
         z.set._.push(o) 
        }; 
        z._ = []; 
        z.set._ = []; 
        $.async = !0; 
        $.setAttribute('charset', 'utf-8'); 
        $.src = '//v2.zopim.com/?1l9izSc2QRurE71l1L7ugke4Soo38dPc'; 
        z.t = +new Date; 
        $.type = 'text/javascript'; 
        e.parentNode.insertBefore($, e) 
       })(document, 'script'); 
};