【jquery 基础 及表单 常用】

表单 JSON序列化

https://www.cnblogs.com/hyyq/p/10945928.html

json 对象转字符串

JSON.stringify(jsonObj);   // 可以将 json 对象转换成字符串

字符串转 json 对象

//方法 1:
var jsonObj = JSON.parse(str);
//方法 2:
var jsonObj = eval('(' + str + ')');

下拉框

1.1 获取选中项的值

var value = $("#selectUser").val();

1.2 获取选中项的文本

var text = $("#selectUser").find("option:selected").text();

1.3 获取第二个option的值

$('#test option:eq(1)').val();

1.4 获取选项总数

var total = $("#selectUser option").length;

1.5 设置选中项
//设置选中下拉框中值为5的选项

$("#selectUser").val(5);

1.6 删除一选项
//删除下拉框中值为3的选项

$("#selectUser option[value='3']").remove();

1.7 清空所有选项

$("#selectUser").empty();

********* 表单 ***********

JQuery遍历页面内所有的input

$("input").each(function () {
$(this).val(0)
})

jquery遍历textarea文本输入框的值
$("#part3").find("input,textarea").each(function(){
alert($(this).val());
}
});

父子页面
JQ:

1,$("#id",parent.document)

2,$(window.parent.document).find("#id")

JS:

1,parent.document.getElementById("id")

posted @ 2022-07-29 11:02  csj425  阅读(36)  评论(0)    收藏  举报