我正在嘗試發(fā)送一個條目的 document.getElementById,它是在我調(diào)用 javascript 函數(shù)并打印它的值的條目之后定義的,但是該函數(shù)提醒我在之后聲明的組件未定義,我該如何訪問它id 并打印它的值?代碼:<!DOCTYPE html><html><body><p>A function is triggered when the user releases a key in the input field. The function transforms the character to upper case.</p>Enter your name: <input type="text" id="fname" onkeyup="myFunction('fname', 'fname2')"><input type="text" id="fname2"><script>function myFunction(first, second) { alert(second.value); var x = document.getElementById(first); x.value = x.value.toUpperCase();}</script></body></html>
如何在聲明組件之前將組件的 id 發(fā)送給函數(shù)?
慕容708150
2023-06-09 10:44:49