考虑我的代码的以下示例代码段。我试过没有运气的parseInt。在这里,我希望javascript在单元格PICweight
中设置一个数字,然后稍后检索它并将其放在不同的单元格totalcabin
中。你可以在这里看到,我想将数字设置为1,但是当代码运行时,它会在NaN
中返回totalcabin
。
<td id="PICweight" type="tel"></td>
<script>
window.onchange = function setfields() {
document.getElementById("PICweight").innerHTML = 1;
var PICweight = document.getElementById("PICweight").value;
var totalcabin = document.getElementById("totalcabin");
totalcabin.innerHTML = +PICweight
}
</script>
答案 0 :(得分:6)
SubstitutionCiphers.hs:95:71: error:
• Couldn't match expected type ‘[Char]’
with actual type ‘Cipher -> Int -> [Char]’
• Probable cause: ‘encodeMessage’ is applied to too few arguments
In the second argument of ‘(++)’, namely ‘encodeMessage (xs cp n)’
In the expression:
[(offsetRight (mod n 26) cp) !! ((letterToNum x) - 1)]
++ encodeMessage (xs cp n)
In an equation for ‘encodeMessage’:
encodeMessage (x : xs) cp n
| n >= 0
= [(offsetRight (mod n 26) cp) !! ((letterToNum x) - 1)]
++ encodeMessage (xs cp n)
| otherwise
= [(offsetLeft (26 - (mod n 26)) cp) !! ((letterToNum x) - 1)]
++ encodeMessage (xs cp n)
SubstitutionCiphers.hs:95:85: error:
• Couldn't match expected type ‘Cipher -> Int -> [Char]’
with actual type ‘[Char]’
• The function ‘xs’ is applied to two arguments,
but its type ‘[Char]’ has none
In the first argument of ‘encodeMessage’, namely ‘(xs cp n)’
In the second argument of ‘(++)’, namely ‘encodeMessage (xs cp n)’
元素没有值属性。在普通html元素(非输入元素)上使用td
时,最终会得到.value
。之后,您使用undefined
隐式将+
投射到一个数字,这会产生undefined
以及随后的观察结果。
您应该使用NaN
而不是值来获取td元素中的文本。
.textContent