<li>
<label class="enterText">供應商類別:</label>
<p class="enterRadio">
<input type="checkbox" value="固定收益" class="type" id="typeA" name="type"/>
<label for="typeA">固定收益</label>
</p>
<p class="enterRadio">
<input type="checkbox" value="浮動收益" class="type" id="typeB" name="type"/>
<label for="typeB">浮動收益</label>
</p>
<p class="enterRadio">
<input type="checkbox" value="基金" class="type" id="typeC" name="type"/>
<label for="typeC">基金</label>
</p>
<p class="enterRadio">
<input type="checkbox" value="保險" class="type" id="typeD" name="type"/>
<label for="typeD">保險</label>
</p>
<div class="Validform_checktip"></div>
</li>
checkbox在後臺直接用數組接收,然後遍歷就可以得到checkbox被選中狀態的一個數組
String[] checkbox= request.getParameterValues("type"); //根據名字獲得checkbox的值,注意是getParameters,後面要加上s,因爲是一個數組
String typeString="";//定義一個數組接收checkbox
for(int i =0;i<checkbox.length;i++) //對checkbox進行遍歷
{
typeString+=checkbox[i]+",";
}
typeString=typeString.substring(0,typeString.length()-1); //截取掉最後一個逗號