Javascript 计数单选按钮不工作

Javascript 计数单选按钮不工作,javascript,jquery,html,Javascript,Jquery,Html,我正在编写一个有100多个问答卡的应用程序,并添加了交通灯按钮,让用户能够思考他们对每个问题/答案的理解程度 <form> <fieldset data-role="controlgroup" data-theme="b" data-type="horizontal" data-mini="true"> <legend>Rate your understanding</legend> <input type="radio" n

我正在编写一个有100多个问答卡的应用程序,并添加了交通灯按钮,让用户能够思考他们对每个问题/答案的理解程度

<form>
<fieldset data-role="controlgroup" data-theme="b" data-type="horizontal" data-mini="true">
    <legend>Rate your understanding</legend>
    <input type="radio" name="traffic-lights" class="red" id="red" value="on" checked="checked">
        <label for="red"><img src="http://new.chemistry-teaching-resources.com/images/red-light18.png" width="18px" height="18px" ></label>
    <input type="radio" name="traffic-lights" class= "orange" id="orange" value="off">
    <label for="orange"><img src="http://new.chemistry-teaching-resources.com/images/Orange-light18.png" width="18px" height="18px"></label>
    <input type="radio" name="traffic-lights" class="green" id="green" value="other">
    <label for="green"><img src="http://new.chemistry-teaching-resources.com/images/green-light18.png" width="18px" height="18px"></label>
</fieldset>
}))

最后,我想记录一下红色/橙色/绿色按钮的点击次数

<p><span class="red_results">0</span> <img src="http://new.chemistry-teaching-resources.com/images/red-light18.png" width="18px" height="18px"> <span class="orange_results">0</span> <img src="http://new.chemistry-teaching-resources.com/images/Orange-light18.png" width="18px" height="18px"> <span class="green_results">0</span> <img src="http://new.chemistry-teaching-resources.com/images/green-light18.png" width="18px" height="18px"></p>    
0

我主要基于一些类似的堆栈溢出示例

我已经让它在JSFIDLE上完美地工作,但在我的应用程序中不起作用

我使用的js是jquery-1.6.4.min.js、jquery.mobile-1.0.min.js和jquery-1.11.3.js,它们在jsiddle上都可以使用

想必,我做错了什么,但我就是看不出来

我剩下的时间是

<script src="jquery-mobile/jquery-1.6.4.min.js" type="text/javascript"></script>

jQuery事件是在jQuery版本1.7中引入的

您正在运行的jQuery版本不支持on()方法。以前版本的jQuery需要或,后者是事件委派的首选方法


如果可以,您应该考虑更新jQuery版本,以使用更多最新功能。

抱歉,我发布了错误的链接。应该是啊,当我打开你的JSFIDLE链接时,它对我有用。谢谢NealC,但这就是问题所在。它在JSFIDLE上工作得很好,我不明白为什么它在我的应用程序页面中仍然不能工作。啊,我的错。我们能看到更多的HTML吗?除非林赛已经解决了你的问题。比如
?你能编辑你的问题并更改那里的链接吗?你在应用程序中使用的jQuery版本与在小提琴上使用的版本相同吗?谢谢LyndseyB。不确定on()事件在我的代码中出现的位置。在jQuery 1.6.4中,它似乎在JSFIDLE上运行良好。我提到了您链接到的JSFIDLE:它使用on()方法。我现在可以看到您已经发布了相关示例的链接。
<script src="jquery-mobile/jquery-1.6.4.min.js" type="text/javascript"></script>