Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在jQuery中设置dom动态生成的图像标记中的路径_Jquery_Html - Fatal编程技术网

如何在jQuery中设置dom动态生成的图像标记中的路径

如何在jQuery中设置dom动态生成的图像标记中的路径,jquery,html,Jquery,Html,我面临的一个问题是,我有一个图像标记,这是我动态制作的,但当我通过SRC属性分配路径时,它不起作用。我怎样才能得到答案?我的代码如下: function GetAllProduct() { $("#AllProductArea").empty(); var Count = 0; $.getJSON("/api/tblProducts/AllProduct", function(data) { $.each(data, function(key, val

我面临的一个问题是,我有一个图像标记,这是我动态制作的,但当我通过SRC属性分配路径时,它不起作用。我怎样才能得到答案?我的代码如下:

function GetAllProduct() {
    $("#AllProductArea").empty();
    var Count = 0;

    $.getJSON("/api/tblProducts/AllProduct", function(data) {

        $.each(data, function(key, val) {
            var pic1Path = '~/ProductsImages/' + val.PrdPic1;
            alert(pic1Path + " PP");
            $('<option>Smlr' + val.PrdName + '</option>').appendTo("#LstPrdSimlarTo");


            $('<div id="btnAreaPrd" class="btnArea"><span id=Product' + Count + ' class="IdHed">' + val.ProductId + '</span><input type="button" id=' + Count + ' value="Get Details " class="btnSaveChanges"><span class="addheddings">Quantity  </span><span class="addheddings">' + val.Quantity + '</span><span id=' + Count + ' class="UpadteHed">Upadate</span><span id=' + Count + ' class="DelHed">Delete</span></div><table id="tblProducts" class="tblLayout"><tr><td><img id=Img' + Count + ' Class="imgOrder"></td><td>  <span id="orderName" class="orderSubHed">' + val.PrdName + '</span></td><td><span id="orderPrice" class="orderSubHed">' + val.PrdDisPrice + '</span></td><td><span id="orderStatus" class="orderSubHed">' + val.StockStatus + '</span></td></tr></table><br><br>').appendTo("#AllProductArea");
            alert(Count + " countValue");
            alert('#Img' + Count);
            $('#Img' + Count).attr('src', pic1Path);

            Count = Count + 1;

        });
    });
函数GetAllProduct(){ $(“#AllProductArea”).empty(); var计数=0; $.getJSON(“/api/TBLPProducts/AllProduct”),函数(数据){ $。每个(数据、函数(键、值){ var pic1Path='~/ProductsImages/'+val.PrdPic1; 警报(pic1Path+“PP”); $('Smlr'+val.PrdName+'')。附加到('LstPrdSimlarTo'); $(''+val.ProductId+'Quantity'+val.Quantity+'UpadateDelete
这里我的pic路径在pic1Path变量中。请帮助我。

您需要设置
src
属性


$(“#Img”+Count).attr('src',pic1Path);
验证
的id

尝试此代码。如果图像源在缓存中,则必须刷新它

pic1Path=pic1Path+"?"+CreateGuid();
$("#Img" + Count).attr('src', pic1Path);
在文档外创建单独的函数。准备好了吗

 function CreateGuid() {  
       function _p8(s) {  
          var p = (Math.random().toString(16)+"000000000").substr(2,8);  
          return s ? "-" + p.substr(0,4) + "-" + p.substr(4,4) : p ;  
       }  
       return _p8() + _p8(true) + _p8(true) + _p8();  
    } 

计数在哪里?对不起,先生,我现在写了一半的代码updated@AkshayTomar在document.ready中调用此函数“GetAllProduct()”时,是否出现任何错误?@AkshayTomar?否则“不工作”不是正确的问题描述。请先阅读所有内容。然后相应地编辑您的问题。它与sirconsole.log(pic1Path)和check resultwhere to write Sir?Sir没有结果,输出相同