jQuery:单击以开头的每个id元素 [英] jquery: click for every id-element starting with

查看:84
本文介绍了jQuery:单击以开头的每个id元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试查找所有以字符串"matchItem_"开头的ID,并为每个ID定义一个点击事件. onclick我想执行带有url参数的脚本并更改此id元素中的图像.不幸的是,我的语法不正确,我也尝试使用.each.function,但没有得到.

i try to find all id's starting with the string "matchItem_" and define a click-event for each. onclick i want wo execute a script with an url param and change the image in this id-element. unfortunatly my syntax isn't right, i also tried with .each.function but i didn't get it.

请参阅我的代码:

$('[id^="matchItem_"]').each {

    $(this).click(){
     //...execute my script.php?urlparam=xx....;
     $(this).find('img').attr('src','/admin/images/ok.png');
    }

}

感谢别人的帮助

提前,米贝克

推荐答案

您不需要each:

$('[id^="matchItem_"]').click(function() {
   // do something
   $(this).find('img').attr('src','/admin/images/ok.png');
});

这篇关于jQuery:单击以开头的每个id元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆