好吧,我有一个table
的董事会。每次玩家进行交易时table
都会更新,因为table
管理玩家的钱。
因此,每当玩家购买股票时,被称为“货币”的variable
增加1。这告诉table
突击显示之前的row
(此为$("#money" + (monies - 1) + "Tab").css("text-decoration", "line-through");
)并在此row
之后创建新的row
($("#money" + (monies - 1) + "Tab").after('<tr id = "money' + stocks + 'Tab"><td id = "money' + stocks + '">' + moneyTotal + '</td></tr>');
})。
好吧,这对于购买股票非常有用。每当有人购买股票时,它就会超过table
row
,之后会创建一个新的table
row
。但是,在卖股票时,我有相同的公式。它会立即更新“货币”variable
,然后点击之前的row
,然后添加另一个货币。这确实很有效,但只是第一次。如果您销售多个库存,它不起作用。
这是我的代码(包括购买和删除股票):
$("#numberPurchaseStockButton").off('click').on('click', function() {
var totalMoney = parseInt($("#purchaseStockMoneyAfterPrice").text());
if (totalMoney >= 0) {
var flipPurchaseStockAnimation = $("#purchaseStockBox");
var entireTable = $("#entireTable");
var numberPurchaseStock = $("#numberPurchaseStock").val()
var purchaseStockSelected = $("#purchaseStockSelect").val();
if (purchaseStockSelected == "Webnet") {
priceSet = webnetPrice;
}
monies++;
$("#money" + (monies - 1) + "Tab").after('<tr id = "money' + stocks + 'Tab"><td id = "money' + stocks + '">' + moneyLeft + '</td></tr>');
if (stocks >= 2) {
$("#" + (stocks - 1)).after('<tr id = "' + stocks + '" class = "yourStockTabs"><td id = "stockAmount' + stocks + '">' + numberPurchaseStock + '</td><td id = "stockType' + stocks + '">' + purchaseStockSelected + '</td><td id = "stockPurchaseCost' + stocks + '">' + cost + '</td><td id = "stockSellPrice' + stocks + '">' + priceSet + '</td></tr>');
}
else {
$("#yourStockTableHeader").after('<tr id = "' + stocks + '" class = "yourStockTabs"><td id = "stockAmount' + stocks + '">' + numberPurchaseStock + '</td><td id = "stockType' + stocks + '">' + purchaseStockSelected + '</td><td id = "stockPurchaseCost' + stocks + '">' + cost + '</td><td id = "stockSellPrice' + stocks + '">' + priceSet + '</td></tr>');
}
$("#money" + (stocks - 1) + "Tab").css("text-decoration", "line-through");
cost = 0;
entireTable.animate({
opacity: 1
}, 1000);
clearInterval(costCalculator);
flipPurchaseStockAnimation.animate({
opacity: 0
}, 1000);
setTimeout(function() {
$("#flipBlueCardBox").show();
}, 1050);
var webnetActivated = false;
var cloneCorpActivated = false;
}
else {
alert("You do not have enough money!");
}
});
});
// activate the remove stock function
var sellStockClicked = false;
$("#sellStockButton").off("click").on('click', function() {
sellStockClicked = true;
alert("Please click on the row of the stock that you would like to sell.\n\nWhen you are finished, click on the Cancel button on the top right.");
$(".yourStockTabs").css("background", "#E50000");
$(".yourStockTabs").css("cursor", "pointer");
$("#cancelButton").css("display", "block");
});
$(document).off("click").on("click", ".yourStockTabs", function() {
if (sellStockClicked === true) {
var ids = $(this).attr("id");
alert(ids);
var stockAmountIds = parseInt($("#stockAmount" + ids).text());
var stockSet = $("#stockType" + ids).text();
var webnetPrice = parseInt($("#webnetPrice").text());
var money = parseInt($("#money" + stocks + "Tab").text());
if (stockSet == "Webnet") {
moneyBack = stockAmountIds * webnetPrice;
moneyTotal = moneyBack + money;
alert(moneyTotal);
}
monies++;
alert(monies);
$("#money" + (monies - 1) + "Tab").css("text-decoration", "line-through");
$("#money" + (monies - 1) + "Tab").after('<tr id = "money' + stocks + 'Tab"><td id = "money' + stocks + '">' + moneyTotal + '</td></tr>');
$(this).css("display", "none");
tabs++;
}
});
$("#cancelButton").click(function() {
if (sellStockClicked === true) {
sellStockClicked = false;
$(".yourStockTabs").css("background", "#FFFFFF");
$(".yourStockTabs").css("cursor", "default");
$("#cancelButton").css("display", "none");
}
});
答案 0 :(得分:-1)
如果我更换所有&#39;股票&#39;与variables
table
的创建有关的row
,有效。