<div>
<input type="text" name="name" id="name" class="name" value="">
</div>
<div>
<input type="radio" class="sex" name="sex" value="1"> 男
<input type="radio" class="sex" name="sex" value="0"> 女
</div>
<div>
<input type="checkbox" class="like" name="like[]" value="1"> 吃饭
<input type="checkbox" class="like" name="like[]" value="2"> 睡觉
<input type="checkbox" class="like" name="like[]" value="3"> 打豆豆
</div>
<div>
<select class="edu" id="edu" name="edu">
<option value="0">请选择学历</option>
<option value="1">初中</option>
<option value="2">高中</option>
<option value="3">本科</option>
<option value="4">研究生</option>
</select>
</div>
<div>
<input type="file" name="upload" class="upload">
</div>
<div>
<div id="test_div" value="123" data_obj="5" data-name="duye"></div>
</div>
<div>
<button class="submit">提交</button>
</div>
<script type="text/javascript" src="node_modules/jquery/dist/jquery.min.js"></script>
<script>
$('.submit').click(function(){
// input text
// var name = $("input[name='name']").val(); // 1. 取值
// var name = $("#name").val();
// var name = $(".name").val();
// $("input[name='name']").attr('value','test'); // 2. 赋值
// input radio
// var sex = $("input[name='sex']:checked").val(); // 1. 取选中的值
// var sex = $(".sex:checked").val();
// $("input[name='sex']").attr('checked','1'); // 2. 选中指定value值的元素
// $("input[name='sex']").get(0).checked = true; // 3. 选中第一个元素
// var sex_status = $(".sex").is(':checked'); // 4. 是否选中
// var sex_status = $(".sex").get(0).checked; // 5. 第几个元素是否选中
// input checkbox
// var like =[]; // 1. 通过each获取所有选中的值
// $('input[name="like[]"]:checked').each(function(){
// like.push($(this).val());
// });
// $("input[name='like[]']").prop("checked",true); // 2. 全选
// $("input[name='like[]']").prop("checked",false); // 3. 取消全选
// $("input[name='like[]']").each(function () { // 4. 反选
// $(this).prop("checked", !$(this).prop("checked"));
// });
// var like_status = $('.like').is(':checked'); // 5. 是否选中
// var like_status = $('.like').get(1).checked; // 6. 第几个元素是否选中
// select
// var edu = $("#edu").val(); // 1. 选中option的value
// var edu = $("#edu option:selected").val(); // 选中option的value
// var edu = $("#edu option:selected").text(); // 2. 选中option的文本
// $(".edu").find("option[value='1']").attr("selected",true); // 3. 选中指定value的项
// $(".edu").find("option:contains('研究生')").attr("selected",true); // 4. 选中指定text的项
// var option = $("<option>").val(5).text("博士"); // 5. 追加option
// $(".edu").append(option);
// 标签属性值
// var str = $("#test_div").attr('value'); // 1. html原有属性value中的值
// var str = $("#test_div").attr('data_obj'); // 2. 自定义属性data_obj中的值
// var str = $("#test_div").data('name'); // 3. 获取data属性中的值
// 文件信息
var fp = $(".upload");
// var length = fp[0].files.length; // 1. 文件数量
// var items = fp[0].files; // 文件信息
var url = URL.createObjectURL(fp[0].files[0]); // 3. 临时地址 可作为图片预览
console.log(url)
})
</script>