jQuery resizing(),访问原始对象
这看起来似乎是显而易见的事情,但我找不到它。使用ressized时,我想保存图像的新宽度,但是如何访问刚刚调整大小的图像的ID属性?这是我的代码:
$('img.article_image').resizable({
aspectRatio: true,
handles: "se",
stop: function(event, ui){
// Here I want to access the ID attribute
// of the img.article_image I am resizing
}});
所以, ui 对象有 ui.helper,我无法使用它。即 ui.helper.attr("id") 或 $(ui.helper).attr("id") 均未定义。我也不能使用 $(this).attr("id"),但我可以使用 $(this).width() 来查看新的宽度,所以这很奇怪。
我做错了什么?当使用draggable()时,我似乎能够以正确的方式访问$(this),但不能使用可调整大小的...有什么建议吗?
This may seem like an obvious thing, but I can't find it. When using resizable, I want to save the new width of the image, but how do I access the ID attribute of the image that I have just resized? This is my code:
$('img.article_image').resizable({
aspectRatio: true,
handles: "se",
stop: function(event, ui){
// Here I want to access the ID attribute
// of the img.article_image I am resizing
}});
So, the ui object has ui.helper, which I can't use. I.e. ui.helper.attr("id") or $(ui.helper).attr("id") are both undefined. I can't use $(this).attr("id") either, but I CAN use $(this).width() to see the new width, so it's very odd.
What am I doing wrong? When using draggable() I seem to be able to access $(this) the correct way, but not with resizable... Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
ui 参数保存调整大小的元素
the ui parameter holds the resized element
我没有使用可调整大小的插件,但如果它遵循与内置 jQuery 事件相同的准则,那么
this
将是对受影响的 DOM 元素的引用。所以你可以获得一个 jQuery 包装的对象,如下所示:I haven't used the resizeable plugin but if it follows the same guidelines as the built-in jQuery events then
this
will be a reference to the affected DOM element. So you can get a jQuery wrapped object like so:在您的情况下,您可以使用以下代码获取
stop
回调内部的 ID:但是,这会复制选择器,但
stop
回调函数传递的参数没有记录调整大小的原始对象的大小。In your case you could just get the ID inside of
stop
callback with this code:This will however duplicate the selector but parameters passed by
stop
callback function doesn't have the record of the original object that was resized.