我知道這是一個非常基本的問題,但我對JavaScript完全陌生,所以我很絕望。我傾注瞭如何解決這個問題,但我無法弄清楚。我需要打電話給第一個標題或第二個標題或兩個名稱。我該怎麼做呢?謝謝!!如何調用一個或兩個或兩個選中的框和文本輸入
<script type="text/javascript">
function ack(){
var name = document.forms[0].elements[0];
var nameValue = name.value;
var title1 = document.forms[0].elements[1];
var title1Value = title1.value;
var title2 = document.forms[0].elements[2];
var title2Value = title2.value;
alert("Thank you for ordering " +title1Value +title2Value +nameValue);
}
</script>
<form>
<h3>Now Available!</h3> <h4>Happy Traveling 2: More Layouts for the Travel Scrapbooker</h4><br/><br/>
<h3>Also available:</h3> <h4>Happy Traveling: Layouts for the Travel Scrapbooker</h4><br/><br/>
<h4>Order today!</h4><br/><br/>
<label>Name:</label>
<input type="text" id="name"/><br/><br/>
<input type="checkbox" id="title1" value="Happy Traveling"/>Happy Traveling<br/>
<input type="checkbox" id="title2" value="Happy Traveling 2"/>Happy Traveling 2<br/><br/>
<input type="submit" value="Submit" onclick="ack();"/>
</form>