需要在javascript中执行操作
我想减去2个值,然后立即用javascript进行计算。 我需要找到一种在JS中以第二个需要在javascript中执行操作,javascript,Javascript,我想减去2个值,然后立即用javascript进行计算。 我需要找到一种在JS中以第二个id为目标的方法,因为我回显了这些选项,所以我是这样做的: <tr> <!-- first row, with css --> <td style="width:50%;">From</td> <td style="width:50%;"> <select name="fromlevel" id="fromlevel" style="w
id为目标的方法,因为我回显了这些选项,所以我是这样做的:
<tr> <!-- first row, with css -->
<td style="width:50%;">From</td>
<td style="width:50%;">
<select name="fromlevel" id="fromlevel" style="width:100%; text-align:center; font-weight:bold;">
<?php
$i = 1;
while ($i < 91) {
echo '
<option value=f' . $i . ' name=f' . $i . '>' . $i . '</option>';
$i++;
}
?>
</select>
</td>
</tr>
<tr> <!-- second row, with css -->
<td>To</td>
<td>
<select name="tolevel" id="tolevel" style="width:100%; text-align:center; font-weight:bold;">
<?php
$i = 1;
while ($i < 91) {
echo '
<option value=t' . $i . ' name=t' . $i . '>' . $i . '</option>';
$i++;
}
?>
</select>
</td>
</tr>
从…起
到
我用f1、f2、f3、f4等以及t1、t2、t3、t4等引用ID。在JS中如何区分它们
如果我只是将第一个
的ID引用为$I,那么下面的JS就可以工作了,我对JS非常不满意,我不知道如何将该引用设为$I
var level_current_prices = {};
for(var i = 1; i <= 90; i++ ) {
level_current_prices[i] = i;
}
function getCurrentLevel() { // current level, from
var levelSetPrice=0;
var theForm = document.forms["priceCalcForm"];
var selectedLevel = theForm.elements["fromlevel"];
levelSetPrice = level_current_prices[selectedLevel.value];
return levelSetPrice;
}
function calculateTotal() {
var LevelPrice = getCurrentLevel();
var divobj = document.getElementById('totalPrice');
divobj.style.display='block';
divobj.innerHTML = "Total Price For the Leveling $"+LevelPrice;
}
function hideTotal() {
var divobj = document.getElementById('totalPrice');
divobj.style.display='none';
}
document.forms['priceCalcForm'].fromlevel.onchange = function () {
calculateTotal();
}
var级别\当前\价格={};
对于(var i=1;我有点被你的问题弄糊涂了。我想你是在说以下几行
for(var i = 1; i <= 90; i++ ) {
level_current_prices[i] = i;
}
我已经有一段时间没有使用php了,所以你也许可以做得更好:D.我不完全理解你想做什么,但是你是否尝试过表单元素[“tolevel”]
?它引用了第二个选择。这不是一个解决方案,但你应该真正引用你的html属性,例如:标题你可以“使用”在JavaScript中,数字作为对象的属性名,它们只是将类型强制转换为字符串。myObj[1]
和myObj['1']
最后引用的是同一个属性。不过,最好指出,在对象中仅使用序列号作为属性值,这意味着您确实可以使用数组。
<?php
$i=1;
$out = "{";
while ($i<91) {
$out .= "\"t".$i."\"=".$i.",";
$i++;
}
$out .="};";
echo "var level_current_prices = ".$out;
?>