我有一个不同字段的表单,如radiobutton,checkbox和 列表菜单(下拉列表)。完成用户输入后,他将单击a 像显示预览的按钮。然后我如何根据选择显示用户输入 jquery中的onclick事件?
<input type = "checkbox" id="stateid" name="stateid" value="">
<input type = "radio" id="gender" value="male">
答案 0 :(得分:0)
我认为这段代码可以帮助你......
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>name</title>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script>
$(document).ready(function(){
$('#preview').click(function(){
$('input[id="stateid"]:checked').each(function() {
console.log(this.value);
});
console.log($('input[id="gender"]:checked').val());
console.log($('option[id="car"]:checked').val());
})
})
</script>
</head>
<body>
<input type = "checkbox" id="stateid" name="stateid" value="first">first<br />
<input type = "checkbox" id="stateid" name="stateid" value="Second">Second<br/>
<input type = "radio" name="gender" id="gender" value="male">male
<input type = "radio" name="gender" id="gender" value="female">female
<br />
<select id="dropdown">
<option id="car" value="volvo">Volvo</option>
<option id="car" value="saab">Saab</option>
</select>
<br />
<button type="button" id="preview">Show Preview</button>
</body>
</html>