jQuery中的prop属性是一个强大的工具,可以用来操作元素的属性。它可以用来获取和设置元素的属性,也可以用来添加、删除或修改元素的属性。
使用prop()获取属性
// 获取id为test的元素的checked属性 var checked = $("#test").prop("checked");
使用prop()设置属性
// 设置id为test的元素的checked属性为true $("#test").prop("checked", true);
使用prop()添加属性
// 给id为test的元素添加disabled属性 $("#test").prop("disabled", true);
使用prop()删除属性
// 删除id为test的元素的disabled属性 $("#test").prop("disabled", false);
使用prop()修改属性
// 修改id为test的元素的checked属性 $("#test").prop("checked", false);
使用prop()方法可以方便地获取、设置、添加、删除或修改元素的属性,它是jQuery中一个强大的工具。