实例 jQuery 使用函数更改选定元素的 CSS 属性

x
 
<!DOCTYPE html>
<html>
<head>
<script src="https://libs.baidu.com/jquery/2.1.4/jquery.min.js"></script>
<script>
$(document).ready(function(){
  $("button").click(function(){
    $("p").css("border-width", function(i){
      return i + 25;
    });
  });
});
</script>
</head>
<body>
<button>Change the border-width property of the p element</button>
<p style="border: 1px solid black;">This is a paragraph.</p>
</body>
</html>
                    

输出结果