简体   繁体   English

不调用简单的jQuery函数

[英]Simple jQuery function not called

There is an old web project I have to add some functionality to, and alot was done using plain javascript. 我必须向其中添加一些旧的Web项目功能,并且很多操作都是使用纯JavaScript完成的。

Because I wanted to start using jQuery, I wrote the following simple test: 因为我想开始使用jQuery,所以编写了以下简单测试:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="ISO-8859-1">
        <title>Radiotest</title>
        <script src="ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
        <script type="text/javascript">
$(document).ready(function(){
    $('#myButton').on('click', function() {
        alert("Test");
        alert($('input[name=Test]:checked', '#myForm').val()); 
    });
});
        </script>
    </head>
    <body>
    <div id="result"></div><br/>
    <form id="myForm">
        <input type="radio" name="Test" value="1"> 1<br>
        <input type="radio" name="Test" value="2"> 2<br>
        <input type="radio" name="Test" value="3"> 3<br>
        <input type="button" id="myButton" value="Check">
    </form>
    </body>
</html>

Unfortunately, when clicking on the button after selecting a radio element the function is not being called, or atleast none of the alerts get displayed. 不幸的是,在选择单选元素后单击按钮时,该功能未被调用,或者至少没有任何警报被显示。

Can you please help me spot the error. 您能帮我发现错误吗? Thank you. 谢谢。

Your src attribute value ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js is invalid. 您的src属性值ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js无效。 You must either include the http:// or // to pickup the currently used protocol: 您必须包含http:////以拾取当前使用的协议:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>

尝试这个:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>

在这种情况下src="http://resource"

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>

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

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