0
應該說Bob Miller
在控制檯爲什麼不通過Console.log結果?
但是,相反,它說Undefined Undefined
我真的很感激,如果有人幫我出這一點。
<body bgcolor='000000'>
<center>
<input placeholder='Enter First Name' value='Bob' class='firstName'>
<input placeholder='Enter Last Name' value='Miller' class='lastName'>
</center>
</body>
<script>
firstname = document.getElementsByClassName('firstName').value;
lastname = document.getElementsByClassName('lastName').value;
result = firstname + ' ' + lastname;
console.log(result);
</script>
getElementsByClassName方法返回HTMLDomArray。您需要執行 'document.getElementsByClassName('className')[0] .value',因爲該數組沒有值 – Gibolt