2017-05-04 111 views
-2

我有下面的代碼app.js文件節點:我想在PHP文件的JavaScript代碼

var embed = require('embed-video'); 

function go() { 




    var c1 = document.getElementById('area1').value; 

    var divElement = document.createElement("div"); 
    divElement.id = "myDiv"; 
    divElement.className = "myDivClass"; 
    divElement.innerHTML = embed(c1); 
    document.body.appendChild(divElement); 
    form1.reset(); 
    var button = document.getElementById("remove"); 
    button.addEventListener("click", function() { 
     divElement.parentNode.removeChild(divElement); 
    }); 
    } 

和index.php文件:

<!DOCTYPE html> 
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" class="hl-en not-logged-in "> 
<head> 
    <meta charset="UTF-8" /> 
    <title>Embedo</title> 
     <script> 

src="app.js" 

    </script> 
<meta name="google-translate-customization" content="293dbcc6d4a40585-2e495f68115e63cb-gd0522d114e7d11d6-e"></meta> 
</head> 

<body class="page-home" style= 
" margin-left: auto; 
    margin-right: auto; 
    width: 35%;background-color: #b0e0e6;"> 



<form id="form1" > 
     <div align="center"> 
      <textarea id="area1" rows="5" placeholder="embed here!"></textarea> 
      <input type="button" value="add video!" onclick="go()" /> 
      <br /> 
      <input id="remove" type="button" value="start over!" onclick="remover()" /> 

     </div> 
    </form> 

</body> 
</html> 

當我按下添加視頻按鈕,它說「去不定義」。不過,我已經在我的php文件中包含了JavaScript文件。我也做了相應的npm安裝,我的模塊都存在。

+1

您的腳本標記錯誤。你應該把它包含在HTML中,如下所示:'

0

做到這一點

,並添加app.js

+0

你在開玩笑...對嗎? – mai