jQuery设置属性值

使用的方法:attr()

1设置单个属性的值

示例1:设置form表单中的acrion属性的值:
html: <form id="form1">

jQuery: $('#form1').attr("action","http://www.baidu.com/");

2设置多个属性的值

示例2:同时设置href和title的值

html: <a id="index">首页</a>

jQuery:

<!-- lang: js -->
$('#index").attr({
<!-- lang: js -->
                "href":"http://www.baidu.com/",
<!-- lang: js -->
                "title":"首页"
<!-- lang: js -->
            });

你可能感兴趣的:(jQuery设置属性值)