我在使用Jquery时遇到了一些麻烦。
我在谷歌上做了一些研究,但从一周以来我没有发现任何问题,所以我决定在那里回答这个问题,也许我会有更多的机会找到问题。
我在使用jquery Uncaught TypeError: Object [object Object] has no method 'onclick'
时出现错误
事实上,我首先在文档的<head>...</head>
中包含了jquery库,如下所示:<script src="lib_js/jquery.js"></script>
然后我写了这个脚本,看到了其他一些使用jquery的脚本(这是我第一次使用它)
<script type="text/javascript">
$(document).ready(function () {
$("img.flag").onclick(function()
{
// Get the src of the image
var src = $(this).attr("id");
// Send Ajax request to backend.php, with src set as "img" in the POST data
$.post("lib_php/session.php", {"lang": src});
})
})
</script>
这个脚本在控制台上向我显示了那个错误
Uncaught TypeError: Object [object Object] has no method 'onclick'
我不知道如何解决那个问题。
任何帮助都将不胜感激。
点击处理程序是使用.click()注册的,而不是.onclick()
-在jQuery API 中没有这样的方法
$("img.flag").click(function(){
// Get the src of the image
var src = $(this).attr("id");
// Send Ajax request to backend.php, with src set as "img" in the POST data
$.post("lib_php/session.php", {"lang": src});
})