2013-03-20 46 views
0

我從一個事業部將動態代碼通過Ajax,我也想加入一些JavaScript,但它的代碼顯示着我的代碼在下面給出的HTML插入..Jquery的無法通過的.html()

$.ajax({ 
       url: "ajax_add_logo_parts.php", 
       data: 'act=getPartImage&part_id='+part_id+'&list_id='+n[1], 
       success: function(msg){ 

        alert($("#mainPartId"+n[1]).html()); 
        $("#mainPartId"+n[1]).append(msg) 
        alert(msg); 
        alert($("#mainPartId"+n[1]).html()); 
        $("#"+n[0]).val(color)     
       } 
      }); 

可變MSG包含一些HTML和JavaScript這在下文給出,但它不能能在HTML

<script type="text/javascript"> 

    var capPartId1 = document.getElementById("capPartId1"); 



    var originalPixelsPart1 = null; 

    var currentPixelsPart1 = null; 



    function changeColorPart1(color) 

    { 

     $('.bill').val(color); 

     if(!originalPixelsPart1) return; 

     var newColorLogo = HexToRGB(color); 



     for(var I = 0, L = originalPixelsPart1.data.length; I < L; I += 4) 

     { 

      if(currentPixelsPart1.data[I + 3] > 0) 

      { 

       currentPixelsPart1.data[I] = originalPixelsPart1.data[I]/255 * newColorLogo.R; 

       currentPixelsPart1.data[I + 1] = originalPixelsPart1.data[I + 1]/255 * newColorLogo.G; 

       currentPixelsPart1.data[I + 2] = originalPixelsPart1.data[I + 2]/255 * newColorLogo.B; 

      } 

     } 



     ctx.putImageData(currentPixelsPart1, 0, 0); 

     capPartId1.src = canvas.toDataURL("image/png"); 

    } 

    function getPixelsPart1(img) 

    { 

     canvas.width = img.width; 

     canvas.height = img.height; 



     ctx.drawImage(img, 0, 0, img.naturalWidth, img.naturalHeight, 0, 0, img.width, img.height); 

     originalPixelsPart1 = ctx.getImageData(0, 0, img.width, img.height); 

     currentPixelsPart1 = ctx.getImageData(0, 0, img.width, img.height); 



     img.onload = null; 

    } 

</script> 

<div class='capPart1 bill_1' id='1' style='position: absolute;z-index: 600;display: block;'><img src='http://localhost/CustCap/Code/customcap/images/capparts/0630112013030101.png' id='capPartId1' onload='getPixelsPart1(this);'></div> 

<input type='hidden' name='bill' id='bill' class='bill' value='' /> 

顯示我可以看到正下方代碼

<div class='capPart1 bill_1' id='1' style='position: absolute;z-index: 600;display: block;'><img src='http://localhost/CustCap/Code/customcap/images/capparts/0630112013030101.png' id='capPartId1' onload='getPixelsPart1(this);'></div> 

<input type='hidden' name='bill' id='bill' class='bill' value='' /> 
+0

把你的JavaScript出你的HTML? – Liam 2013-03-20 11:28:01

+0

msg的價值是什麼? – Sharun 2013-03-20 11:28:14

+0

味精包含第二個代碼分鐘html和javascript – 2013-03-20 11:29:12

回答

0

試試這個

 $.ajax({ 
      url: "ajax_add_logo_parts.php", 
      data: 'act=getPartImage&part_id='+part_id+'&list_id='+n[1], 
      success: function(msg){ 

       alert($("#mainPartId"+n[1]+"").html()); 
       $("#mainPartId"+n[1]+"").append(msg) 
       alert(msg); 
       alert($("#mainPartId"+n[1]+"").html()); 
       $("#"+n[0]+"").val(color)     
      } 
     }); 
+0

同一個錯誤不顯示我的Javascript – 2013-03-20 11:35:16

+0

你檢查CONSOL? – 2013-03-20 11:42:52

+0

是我得到了安慰和警戒也:( – 2013-03-20 11:43:28

0

type:post/get缺少嘗試添加此:

$.ajax({ 
    type:"GET", 
    url: "ajax_add_logo_parts.php", 
    data: 'act=getPartImage&part_id=' + part_id + '&list_id=' + n[1], 
+0

不工作的好友:( – 2013-03-20 11:44:13