jQuery文档分析4-属性的动态设置
来源:互联网 发布:淘宝红人馆 编辑:程序博客网 时间:2024/06/14 09:05
例子1: 动态设置img的src属性 其他dom元素雷同用于动态属性的设置
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript">
$(document).ready(
function(){
$("#load").click(function(){
$("img").attr("src","admin.png") ; //设置img的src属性
$("img").attr("src") ;//返回所有img的src属性....
}
) ;
$("#unload").click(function(){
$("img").removeAttr("src") ; //删除img的src属性//
}) ;
}
) ;
</script>
<title>Insert title here</title>
</head>
<body>
<img src="">
<button id="load">显示</button>
<button id="unload">删除</button>
</body>
</html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript">
$(document).ready(
function(){
$("#load").click(function(){
$("img").attr("src","admin.png") ; //设置img的src属性
$("img").attr("src") ;//返回所有img的src属性....
}
) ;
$("#unload").click(function(){
$("img").removeAttr("src") ; //删除img的src属性//
}) ;
}
) ;
</script>
<title>Insert title here</title>
</head>
<body>
<img src="">
<button id="load">显示</button>
<button id="unload">删除</button>
</body>
</html>
2、html text val的用法区别 ......
$('p').html(); 是获取所有p标签下的html代码包括标签....
$('p').html("<a>xxx<a>"); 设置p下的html内容,和dom的innerHTML属性相对应
$('p').text( ); 同上设置或者获取..p标签下的所有文本...或者设置 ....这列的<a>dxx</a>都会解析成文本
$("p").text("Hello world!");
$("input").val(); 获取或者设置 表单元素的值..具体可以结合筛选..选择器 选择我们的元素然后再获取或者设置值
$("input").val("hello world!");
3、通过动态设置dom元素的class 设置css属性
<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><script type="text/javascript" src="js/jquery.js"></script><script type="text/javascript"> $(document).ready( function(){ $("#load").click(function(){ $("p").addClass("styleme") ; //增加class属性 styleme } ) ;
$("#unload").click(function(){ $("p").removeClass("styleme") ; //卸载css属性 }) ; } ) ;</script><style type="text/css">.styleme{ font-size: 20px ; color: blue; }</style><title>Insert title here</title></head><body><p>23232d的</p><button id="load">显示</button>
<button id="unload">卸载</button></body></html>
$("p").toggleClass("selected"); //表示如果累不存在就添加一个类
4、设置/获取在匹配的元素集中的第一个元素的属性值。
$("input[type='checkbox']").prop("checked"); 获取input元素中type=checkbox 元素集合的第一个元素的checked属性值
$("input[type='checkbox']").prop("disabled", false); 禁用checkbox$("input[type='checkbox']").prop("checked", true); 设置checkbox选中、///
jQuery文档中目前就介绍了这些属性设置方法
- jQuery文档分析4-属性的动态设置
- jQuery中动态设置表格的属性
- jquery取<input>的readOnly属性,O要大写(动态设置readonly属性无效)
- .JQuery文档分析2--JQuery核心与属性操作
- JQuery文档分析2--JQuery核心与属性操作
- js+jquery动态设置/增加/删除/获取元素属性的两种方法集锦对比(动态onclick属性设置+动态title设置)
- jQuery 设置属性的值
- 动态设置HyperLink的属性
- DataGridView1的属性动态设置
- 动态设置js的属性
- .jQuery文档分析4-文档处理
- jquery下 动态显示jqGrid 以及jqGrid的属性设置容易出现的问题
- jquery下动态显示jqGrid以及jqGrid的属性设置容易出现问题的解决方法
- 单文档的属性页Dialog设置
- jquery 设置控件的disabled属性
- jquery设置input disabled属性的示例
- jquery属性的获取与设置
- jQuery - 设置div的内容和属性
- Java创建文件与目录
- http://s.yanghao.org/program/viewdetail.php?i=104448
- 以開源碼 dansguardian+tinyproxy 實作色情守門員
- Linux - 后台运行sql
- 《搜索》——好看,值得推荐
- jQuery文档分析4-属性的动态设置
- android开发中,项目里的文件不能导出到本地问题
- VMware Workstation - RAC的共享磁盘设置
- ORA-12514 TNS 监听程序当前无法识别连接描述符中请求服务 的解决方法
- Oracle 10G RAC - SYSAUX进行完全恢复的问题
- poj 2069 super star 模拟退火
- HDOJ 1712 ACboy needs your help (分组背包)
- poj 2420 A Star not a Tree? 模拟退火
- 如何高效地阅读技术类书籍与博客