我在该标签内有 span 标签,新的图像标签是动态生成的,但我需要获取该标签的图像 src
是否可能
<span id ="Imagespan">
<image scr="some.png" alt="some" />
<span>
最佳答案
你的意思是img
而不是image
,是的,你可以,试试:
$('#Imagespan').find('img').attr('src');
//or also
$('#Imagespan').find('img').prop('src');
或者使用直接选择器,例如:
$('#Imagespan img').prop('src');
注意:无论元素是否动态创建,获取“属性/属性”的方法都是相同的。
.attr() changes attributes for that HTML tag.
.prop() changes properties for that HTML tag as per the DOM tree.
As the example in this link suggests. An input field can have the attribute "value". This will equal the default value you entered. If the user changes the value in the input field, the property "value" changes in the DOM Tree, but the original attribute is left remaining.
<强> Source
关于javascript - 通过动态生成的标签获取图片源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41023718/