我已經制作了一個表單,當您按下go鍵時,鍵入文本框的內容會出現在屏幕上,只有它不起作用,這裏是JavaScript代碼: var sentence1; var sentence2; var middlesentence;使用JavaScript向網頁輸入句子
function paraFunction(setence1, middlesentence, setence2)
{
sentence1 = "You plan is to ";
sentence2 = " and you must succeed at all costs";
middlesentence = form.strPara.value;
paraShow();
}
function paraShow()
{
document.getElementById('paraAns').innerHTML = (sentence1 + middlesentence + sentence2);
}
下面是HTML代碼:
<div id="innerbody">
</div>
<h1>Testing Parameters</h1>
<p>In this example, I will be testing parameters, below you will see a form, asking you to enter a sentence, little do you know, that when you click on the form button, a sentence will be completed below, with your sentence in the middle... oops!</p>
<form type="paraForm" method="get">
<input type="text" placeholder="Input your sentence here" id="strPara"/>
<input type="button" value="Go!" name="paraFunction" onClick="paraFunction(this.form);"/>
</form>
<p id="paraAns"></p>
</div>
你的問題是與範圍。 'sentence1'和所有其他變量超出了第二個函數的範圍。 – BenM 2013-03-07 16:37:30