14--The attr() method of Jquery's style operation

This method has been mentioned before. Here is only an example:

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>使用attr()给指定的元素设置属性</title>
    <script src="jquery-1.11.3.js"></script>
</head>
<body>
    <ul id="fruit">
        <li title="pg">苹果</li>
        <li title="zj">橘子</li>
        <li>香蕉</li>
    </ul>
    <script>
        $(function(){
     
     
            /*使用attr()给指定的元素设置style属性*/
            $("li:eq(2)").attr("title","xj").attr("style","color:red;font-size:20px;");
        });
    </script>
</body>
</html>

Guess you like

Origin blog.csdn.net/qwy715229258163/article/details/113878427