attr(key,func)方法在所有匹配的元素上将单个属性设置为计算值。
selector.attr( key, func )
这是此方法使用的所有参数的描述-
key - 要设置的属性的名称。
func - 返回要设置的值的函数。此函数将有一个参数,它是当前元素的索引。
<html> <head> <title>The Selecter Example</title> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"> </script> <script type="text/javascript" language="javascript"> $(document).ready(function() { $("table").attr("border", function(index) { return "4px"; }) }); </script> </head> <body> <table> <tr><td>This is first table</td></tr> </table> <table> <tr><td>This is second table</td></tr> </table> <table> <tr><td>This is third table</td></tr> </table> </body> </html>
这将产生以下输出-
链接:https://www.learnfk.comhttps://www.learnfk.com/jquery/attr-key-function.html
来源:LearnFk无涯教程网
This is first table |
This is second table |
This is third table |
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)
Spring Boot与Kubernetes云原生微服务实践 -〔杨波〕