我尝试从输入的费用和名称中删除所选对象。使用deleteObject按钮。但我不知道怎么做,有没有办法做到这一点?
<canvas id="c" width="780" height="720" style="border:1px solid #aaa"></canvas>
<img class="items_img" src="photo/images.jpg" data-type="500" data-name="photo1" />
<img class="items_img" src="photo/images1.jpg" data-type="2000" data-name="photo2" />
<img class="items_img" src="photo/images2.jpg" data-type="3000" data-name="photo3" />
<p class="btn btn-primary" onClick="deleteObject()">Delete</p>
<strong>Costs </strong>: <input type="text" name="cost" id="cost"/>
<strong>Names </strong>: <input type="text" name="name" id="name"/>
此JavaScript代码。
function deleteObject() {
canvas.getActiveObject().remove();
discost.push(z1[0]);
console.log(discost);
}
function addAllToCanvas() {
check3 = 1;
var i;
for (i = 0; i < elements.length; i += 1) {
canvas.add(elements[i]);
}
这个Jquery代码。
var totalprice= 0;
var totalname = [];
$(document).ready(function(){
$('.items_img').click(function(){
var name = $(this).attr('data-name');
totalname.push(name);
if (totalname == ''){
$('#name').val('');
} else {
$('#name').val(totalname);
}
var price = $(this).attr('data-type');
totalprice = totalprice + parseInt(price);
if (totalprice == 0) {
$('#cost').val('');
} else {
$('#cost').val(totalprice);
}
}
};