0
嗨,我是的新手,並嘗試通過檢索點擊按鈕的值或名稱將PHP
計算的值發送到JS
函數。得到一個按鈕的名稱或值,以包含一個PHP變量的js函數
PHP文件:
<html>
<head>
<script src="js/script.js">
</script>
</head>
<body>
<table width="500" align="center" cellpadding="5" cellspacing="0" border="0">
<tr>
<td width="10%"><strong>#</strong></td>
<td width="30%"><strong>Name</strong></td>
<td width="10%"><strong>Price</strong></td>
<td width="10%" align="center" colspan="3"><strong>Quantity</strong></td>
</tr>
<?php
$shopgold = $userRow['gold'];
$pricegold = 255;
$maxkopengold = $shopgold/$pricegold;
?>
<tr>
<td><img src="metals/gold.png" width="100%"></td>
<td>Gold</td>
<td><?php echo $pricegold; ?></td>
<td><button name="goldValue" onClick="countDownGold()" value="<?php echo $maxkopengold; ?>">-</button></td>
<td align="center">(<span id="goldValue">0</span>/<?php echo $maxkopengold; ?>)</td>
<td><button name="goldValueUp" onClick="countUpGold()" value="<?php echo $maxkopengold; ?>">+</button></td>
</tr>
</table>
</body>
</html>
JS /的script.js
function countUpGold() {
var currentVal = document.getElementById("goldValue").innerHTML;
var maxVal = jQuery(this).attr("name");
var elements = document.getElementsByName ("goldValueUp");
newVal = currentVal;
alert(this.value);
newVal++;
if (currentVal < maxVal) {
newVal++;
}
document.getElementById("goldValue").innerHTML = newVal;
}
function countDownGold() {
var currentVal = document.getElementById("goldValue").innerHTML;
addVal = 1;
var newVal = 0;
if (currentVal > 0) {
newVal = currentVal - addVal;
}
document.getElementById("goldValue").innerHTML = newVal;
}
我得到了+
和-
按鈕的工作,但現在我想最大的集(對象的可用貨幣/價格),然後設置爲PHP
變量,該變量將用作按鈕的名稱或值。像buttonname.value
我希望我有道理。 在此先感謝