简体   繁体   English

包括来自外部资源的Jquery库

[英]Including Jquery Library from a external scource

I am trying to include the following jquery library: 我正在尝试包括以下jquery库:

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

When I run the bellow code alert is not displayed: 当我运行下面的代码时,警报不会显示:

<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>

However when I run the same code without the reference to the jquery library the alert is displayed: 但是,当我运行相同的代码而不引用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>

After reading comments I change the code to: 阅读注释后,我将代码更改为:

    <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>

With this new code I manage to make alert(123) display. 使用此新代码,我设法使alert(123)显示。 But When I try to use a alert($("#card_holder_name").val()); 但是当我尝试使用警报时($(“#card_holder_name”)。val()); I get "ReferenceError: $ is not defined" I can't use any jquery function. 我收到“ ReferenceError:未定义$”,我无法使用任何jquery函数。

Have you tried : 你有没有尝试过 :

<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>

Edit : This works without error : 编辑 :这工作没有错误:

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

In this line: 在这一行:

<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>

you forgot the ending and starting script tags. 您忘记了结束和开始脚本标签。 Correct it to: 更正为:

<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>

If you put a script source that tag will only run the script at that source, so you simply need to add a third script tag. 如果放置脚本源,则该标记将仅在该源上运行该脚本,因此您只需要添加第三个脚本标记。 Your code: 您的代码:

<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>

should become this instead: 应该变成这个:

<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>

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

The src attribute is optional. src属性是可选的。 If it is present, then its value is a url which identifies a .js file. 如果存在,则其值为标识.js文件的url

The content between the <script src="url"> and the </script> should be blank. <script src="url"></script>应为空白。 If it contain somethings.it is ignored 如果包含某物,则将其忽略

If the src attribute is not present, then the content text between the <script> and the </script> is compiled and executed. 如果不存在src属性,则将编译并执行<script></script>之间的内容文本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM