我写过这样的代码。 <img id='test_img' src='../../..' />
我想在加载图像时获取此图像的 ID,例如,
$(img).load(function() {
// Here I want to get image id i.e. test_img
});
你能帮帮我吗?
谢谢。
最佳答案
$(img).load(function() {
var id = $(this).attr("id");
//etc
});
祝你好运!
编辑:
//suggested by the others (most efficient)
var id = this.id;
//or if you want to keep using the object
var $img = $(this);
var id = $img.attr("id")
关于javascript - 如何使用 jQuery 获取图像 ID?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3890886/