前端前端!!!

manshousu 2017-07-21 05:15:06
	<tr>
<td id = confirmPhoto>123</td>
</tr>
</div>
<script type="text/javascript">
$(function(){
$.ajax({
url:context+'/intelligent/BillOfLadingAction!overPhotoPath.shtml',
data:{
tableId:tableId
},
dataType:'json',
success:function(data){
if(data!=null && data!=''){
var photoPath = JSON.stringify(data);
//alert(photoPath);
var array = photoPath.split(';');
alert(array);
for(var i=0;i<array.length;i++){
var img = "<img class='reportImg' style='width:70px;height: 70px;' src='' />";
$('#confirmPhoto').append('<img class="reportImg" style="width:70px;height: 70px;" src="" />');
}
$(".reportImg").each(function(index){
$(this).attr("src",array[index]);
});
}
}
})
});



为什么append不上??!!
...全文
158 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
A笔记 2019-02-22
  • 打赏
  • 举报
回复
我刚append也报错为空,不明白为什么,js也在下面引入的,自己觉得明明很对,找不到原因真的好痛苦,不知道什么时候哪个好心人出一份append的详细教程
jio可 2017-07-21
  • 打赏
  • 举报
回复
$('#confirmPhoto').append(....)代码上写的是append到id等于confirmPhoto的td上面。。。。你上图的是class等于photoPath.... $('.photoPath').html(html.join(""));
manshousu 2017-07-21
  • 打赏
  • 举报
回复
引用 5 楼 u012418098 的回复:
上面的代码并不是append不上去,是因为img标签是动态加上去的,直接使用.reportImg根本获取不到img对象当然就不可以append了。$(table).find('.reportImg').each(function(){
$(this).attr("src",array[index]);
});这样就没问题,但是明明一步可以做的事情分成了两步!! 直接循环生成img标签的时候可以同时设置src的值。。。。


如图就是append不上去,直接赋值的建议采用了
jio可 2017-07-21
  • 打赏
  • 举报
回复
上面的代码并不是append不上去,是因为img标签是动态加上去的,直接使用.reportImg根本获取不到img对象当然就不可以append了。$(table).find('.reportImg').each(function(){ $(this).attr("src",array[index]); });这样就没问题,但是明明一步可以做的事情分成了两步!! 直接循环生成img标签的时候可以同时设置src的值。。。。
manshousu 2017-07-21
  • 打赏
  • 举报
回复
引用 2 楼 u013116426 的回复:
什么问题
看楼下
manshousu 2017-07-21
  • 打赏
  • 举报
回复
引用 1 楼 u012418098 的回复:

<tr>
        <td id = "confirmPhoto">123</td>
    </tr>
</div>
<style>
.reportImg{
width:70px;
height:70px;
}
</style>
<script type="text/javascript">
$(function(){
    $.ajax({
        url:context+'/intelligent/BillOfLadingAction!overPhotoPath.shtml',
        data:{
            tableId:tableId //没看到有这个id值??
        },
        dataType:'json',
        success:function(data){
                if(data!=null && data!=''){
                    var photoPath = JSON.stringify(data);
                    //alert(photoPath);
                    var array = photoPath.split(';');
                    var html = [];
                    array.forEach(function(item){
                      html.push('<img class="reportImg" src="'+item+'"');
                    });
                    $('#confirmPhoto').html(html.join(""));
                }
            }
    })
});
id = "confirmPhoto"加引号
tableId我在上边获取了,不要担心 回参什么的都没问题,就是到append的时候并没有起作用
___紫菜 2017-07-21
  • 打赏
  • 举报
回复
什么问题
jio可 2017-07-21
  • 打赏
  • 举报
回复

<tr>
        <td id = "confirmPhoto">123</td>
    </tr>
</div>
<style>
.reportImg{
width:70px;
height:70px;
}
</style>
<script type="text/javascript">
$(function(){
    $.ajax({
        url:context+'/intelligent/BillOfLadingAction!overPhotoPath.shtml',
        data:{
            tableId:tableId //没看到有这个id值??
        },
        dataType:'json',
        success:function(data){
                if(data!=null && data!=''){
                    var photoPath = JSON.stringify(data);
                    //alert(photoPath);
                    var array = photoPath.split(';');
                    var html = [];
                    array.forEach(function(item){
                      html.push('<img class="reportImg" src="'+item+'"');
                    });
                    $('#confirmPhoto').html(html.join(""));
                }
            }
    })
});
id = "confirmPhoto"加引号

87,902

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧