我有下面的HTML代碼:獲取輸入和選擇值在JavaScript函數的HTML代碼如下
<div class="elgg-sidebar">
<h3><b>Source: </b></h3>
<input type="checkbox" id="internship[source][]" name="internship[source][]" value="S1" checked=""> S1
<input type="checkbox" id="internship[source][]" name="internship[source][]" value="S2" checked=""> S2
<input type="checkbox" id="internship[source][]" name="internship[source][]" value="S3" checked=""> S3
<h3><b>Internship Type: </b></h3>
<input type="checkbox" id="internship[int_wrk_typ][]" name="internship[int_wrk_typ][]" value="WT1" checked=""> WT1
<input type="checkbox" id="internship[int_wrk_typ][]" name="internship[int_wrk_typ][]" value="WT2" checked=""> WT2
<input type="checkbox" id="internship[int_wrk_typ][]" name="internship[int_wrk_typ][]" value="WT3" checked=""> WT3
<h3><b>Location: </b></h3>
<select style="width:200px;padding: 5px;font-size: 1.1em;color: #666;border: 1px solid #ccc;-webkit-border-radius: 5px;-moz-border-radius: 5px;border-radius: 5px;-webkit-box-sizing: border-box;-moz-box-sizing: border-box;box-sizing: border-box;" name="int_location" id="internship[int_location]">
<option value="%">Any</option>
<option value="Work from Home">Work from Home</option>
<option value="Loc1">Loc1</option>
<option value="Loc2">Loc2</option>
</select>
<h3><b>Dates: </b></h3>
Start Date:
<input value="" type="text" name="int_start" id="internship[int_start]" class="elgg-input-date popup_calendar" data-datepicker-opts="">
End Date:
<input value="" type="text" name="int_end" id="internship[int_end]" class="elgg-input-date popup_calendar" data-datepicker-opts="">
<h3><b>Keywords: </b></h3>
<input value="" type="text" name="keyword" id="internship[keyword]" class="elgg-input-text">
<input type="button" onclick="onClick_Search()" class="elgg-button elgg-button-submit" value="Search">
<input type="button" onclick="onClick_Reset()" class="elgg-button elgg-button-delete float-alt" value="Reset">
</div>
現在,我希望得到上述所有輸入,選擇參數的JavaScript函數。我試過document.getElementById("internship").value
和document.getElementById("internship[]").value
但我無法獲得參數。我甚至嘗試使用document.getElementById("internship[source]").value
和document.getElementById("internship[source][]").value
來獲得單個參數,但仍然運氣不佳。
任何人都可以幫助我解決這個問題嗎?
'id'屬性的行爲與'name'屬性不一樣,每個'id'應該是唯一的。 –
ID應該是唯一的。此外,我認爲ID中不允許有特殊字符 – danielspaniol