将高度和宽度设置为img
在下面的代码中,我想将高度和宽度设置为50像素到此图像。将高度和宽度设置为img
请帮我做到这一点。
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "InvoiceDetailsNew2.aspx/GenerateNewBarcodeImage",
data: "{'BarCodeNumber':'" + Barcode + "'}",
dataType: "json",
async: false,
success: function (data) {
var orders = JSON.parse(data.d);
//alert(data);
var height = 50;
alert(orders);
//imgContent = orders;
imgContent = "<img "
+ "src='" + "data:image/jpg;base64,"
+ orders + "'/>";
},
error: function (result) {
alert("Error in Product Loading");
}
});
尝试这个 -
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "InvoiceDetailsNew2.aspx/GenerateNewBarcodeImage",
data: "{'BarCodeNumber':'" + Barcode + "'}",
dataType: "json",
async: false,
success: function (data) {
var orders = JSON.parse(data.d);
//alert(data);
var height = 50;
var width= 50;
alert(orders);
//imgContent = orders;
imgContent = "<img height='"+height+ "' width='"+width+"'"
+ "src='" + "data:image/jpg;base64,"
+ orders + "'/>";
},
error: function (result) {
alert("Error in Product Loading");
}
});
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "InvoiceDetailsNew2.aspx/GenerateNewBarcodeImage",
data: "{'BarCodeNumber':'" + Barcode + "'}",
dataType: "json",
async: false,
success: function (data) {
var orders = JSON.parse(data.d);
//alert(data);
var height = 50;
alert(orders);
//imgContent = orders;
imgContent = "<img "
+ "src='" + "data:image/jpg;base64,"
+ orders + "'/>";
$(imgContent).height(50).width(50); // set using jquery methods
},
error: function (result) {
alert("Error in Product Loading");
}
});
你需要做这样的事情: -
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "InvoiceDetailsNew2.aspx/GenerateNewBarcodeImage",
data: "{'BarCodeNumber':'" + Barcode + "'}",
dataType: "json",
width: "50",
height:"50",
async: false,
success: function (data) {
var orders = JSON.parse(data.d);
//alert(data);
var height = 50;
alert(orders);
//imgContent = orders;
imgContent = "<img " + "src='" + "data:image/jpg;base64," + orders + "'/>";
},
error: function (result) {
alert("Error in Product Loading");
}
});
希望它可以帮助
它不工作 – 2015-04-02 06:58:11
尝试更新的代码 – BNN 2015-04-02 07:03:22
您可以使用内联样式在创建图像标签。
imgContent = "<img "
+ "src='" + "data:image/jpg;base64,"
+ orders +
+ " height='50' width='50'" + "'/>";
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "InvoiceDetailsNew2.aspx/GenerateNewBarcodeImage",
data: "{'BarCodeNumber':'" + Barcode + "'}",
dataType: "json",
async: false,
success: function (data) {
var orders = JSON.parse(data.d);
//alert(data);
var height = 50;
alert(orders);
//imgContent = orders;
imgContent = "<img "
+ "src='" + "data:image/jpg;base64,"
+ orders +
+ " height='50' width='50'" + "'/>";
},
error: function (result) {
alert("Error in Product Loading");
}
});
摄像设定时,不显示高度和宽度 – 2015-04-02 06:58:59
对不起,我错过了一个报价。我现在已经更新了答案。 – Pugazh 2015-04-02 07:01:07
它不工作 – 2015-04-02 06:58:23
能否请你拨弄它 – 2015-04-02 06:59:13