jquery 属性操作~
来源:互联网 发布:淘宝加盟诈骗霞浦 编辑:程序博客网 时间:2024/05/03 05:44
<script> function t1(){ $('a:first').attr('href','http://www.baidu.com'); //只改一个属性的话 就用逗号 修改多个的属性用 js 的对象 即json 格式来赋值!类似css } function t2(){ //$('a:first').attr({'href':'http://www.baidu.com','background':'red'}) ///'background':'red' 这个是错误的!这里应该是a的属性 而不是CSS属性!! $('a:first').attr({'href':'http://www.baidu.com','alt':'baidu.com'}) //href alt 属性~ } function t3(){ $('input:lt(3)').attr('disabled','disabled') } function t4(){ $('input:not(:last)').attr('disabled',false); }</script></head><body> <h1>属性操作</h1> <ul> <li><a href="#">百度</a></li> </ul> <img src="#" /><br /> <input type="button" value="改变链接" onclick="t1();" /> <input type="button" value="变成百度" onclick="t2();"> <input type="button" value="禁用按钮" onclick="t3();"> <input type="button" value="启用按钮" onclick="t4();"></body>