2016-08-08 64 views
0

我想包括以下jQuery庫:包括jQuery庫從外部scource

http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js

當我運行不顯示婁代碼警報:

<div style="float: left; margin-left:0px; width:20px; padding-top: 10px;"> 
    <form id="payment_form" action="https://arembepe.net/Tester3.php" method="POST"> 
     Número do cartão: <input type="text" id="card_number"/> 
     <br/> 
    </form> 
</div> 

<script src="https://assets.pagar.me/js/pagarme.min.js"></script><script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"> 
alert(123); 
</script> 

然而,當我運行相同的代碼,而不參考jQuery庫提示顯示:

<div style="float: left; margin-left:0px; width:20px; padding-top: 10px;"> 
    <form id="payment_form" action="https://arembepe.net/Tester3.php" method="POST"> 
     Número do cartão: <input type="text" id="card_number"/> 
     <br/> 
    </form> 
</div> 

<script src="https://assets.pagar.me/js/pagarme.min.js"></script><script> 
alert(123); 
</script> 

閱讀評論後,我改變了代碼:

<div style="float: left; margin-left:0px; width:20px; padding-top: 10px;"> 
     <form id="payment_form" action="https://arembepe.net/Tester3.php" method="POST"> 
      Número do cartão: <input type="text" id="card_number"/> 
      <br/>   
     </form> 
    </div> 

    <script src="https://assets.pagar.me/js/pagarme.min.js"></script> 
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> 
    <script> 
       alert($("#card_holder_name").val()); 
    </script> 

有了這個新代碼,我設法使警報(123)顯示器。但是,當我嘗試使用警報($(「#card_holder_name」).val());我得到「ReferenceError:$未定義」我不能使用任何jquery函數。

+0

如果包含'src'屬性值,'

0

在這一行:

<script src="https://assets.pagar.me/js/pagarme.min.js"></script> 
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"> 
    alert(123); 
    </script> 

您忘記結束和開始的腳本標記。它正確的:

<script src="https://assets.pagar.me/js/pagarme.min.js"></script> 
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> 
<script> 
    alert(123); 
</script> 
0

如果你把該標籤將只在該源運行腳本,所以你只需要添加第三個腳本標籤的腳本源。您的代碼:

<div style="float: left; margin-left:0px; width:20px; padding-top: 10px;"> 
    <form id="payment_form" action="https://arembepe.net/Tester3.php" method="POST"> 
     Número do cartão: <input type="text" id="card_number"/> 
     <br/> 
    </form> 
</div> 

<script src="https://assets.pagar.me/js/pagarme.min.js"></script><script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"> 
alert(123); 
</script> 

應該反而成了這樣:

<div style="float: left; margin-left:0px; width:20px; padding-top: 10px;"> 
    <form id="payment_form" action="https://arembepe.net/Tester3.php" method="POST"> 
     Número do cartão: <input type="text" id="card_number"/> 
     <br/> 
    </form> 
</div> 

<script src="https://assets.pagar.me/js/pagarme.min.js"></script><script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> 
<script> 
alert(123); 
</script> 
0

<script src="url"></script>

src屬性是可選的。如果存在,則其值爲url,其標識.js文件。

<script src="url"></script>之間的內容應該爲空白。 如果包含somethings.it被忽略

如果src屬性不存在,那麼<script></script>之間的內容文字編譯和執行。