表单提交中的radio、select下拉框和checkbox复选框数据的获取

radio:
 

<tr>
				<td>公司性质</td>
				<td>
					<input type="radio" id="pro" name="pro" value="1">国有企业
					<input type="radio" id="pro" name="pro" value="2">国有控股企业
				</td>
			</tr>
			
			<tr>
				<td></td>
				<td>
				<input type="radio" id="pro" name="pro" value="3">外资企业
				<input type="radio" id="pro" name="pro" value="4">私营企业
				</td>
			</tr>

js:

var pro=$("input:radio[name='pro']:checked").val();

CheckBox:

<tr>
				<td>行业</td>
				<td>
					<input type="checkbox" name="hy" value="1" class="easyui-validatebox" required="true">医疗
					<input type="checkbox" name="hy" value="2" class="easyui-validatebox" required="true">物流
					<input type="checkbox" name="hy" value="3" class="easyui-validatebox" required="true">煤炭
					<input type="checkbox" name="hy" value="4" class="easyui-validatebox" required="true">钢铁
				</td>
			</tr>

js:

var hang=[];
		$("input:checkbox[name='hy']:checked").map(function(){
			hang.push($(this).val());
		});
		var hys=hang.join("-");

通过ajsx发送到Servlet:

String hy = request.getParameter("hys");
		String[] hyList = hy.split("-");
		for (String string : hyList) {
			int hid = Integer.parseInt(string);
			
			empService.addCom_Hy(cid, hid);
			
		}

select:

<td>
						<select id="sex" name="sex">
							<option value="男">男</option>
							<option value="女">女</option>
						</select>
					</td>

js:

var sex=$("#sex").val();

猜你喜欢

转载自blog.csdn.net/amor_fatii/article/details/80639386