我需要在可编辑iframe的选择中使用imgs进行一些操作。我可以使用所有图像(例如这里是代码)
$(iframe).contents().find('img').attr('alt', 'new alt')
但我只需要在用户选择中进行img。请帮帮我。感谢
答案 0 :(得分:1)
当用户选择使用
获取代码以将选择类添加到用户选择的图像中时//inserted within your selection method
$(iframe).contents().find('img').removeClass('selectionClass');
//this removes all previously selected images
//unless you have a deselection method in which case you don't need this,
//you would need to add $(this).removeClass('selectionClass') to the deselection
$(this).addClass('selectionClass');
//adds it to currently selected images
然后在选择要编辑的图像时使用:
$(iframe).contents().find('img.selectedClass').attr('alt', 'new alt');
答案 1 :(得分:0)
为什么不给你的标签赋一个id,然后用jQuery调用它,然后设置alt属性。例如:
<img id="myImageId"/>
$("#myImageId").attr("alt","This is an image!");