我正在通过 Ajax 从一个 Div 添加动态代码,我还想添加一些 javascript,但它无法显示在代码上,我的代码如下所示。
$.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='' />