废话不多说了,具体代码如下所示:
<html> <head> <script type="text/javascript" src="jquery-1.10.2.min.js"></script> <script type="text/javascript"> /** jquery 通过当前标签属性名,获取属性的值 */ function attrsbyjquery(obj){ var v1 = $(obj).attr(dbname); var v2 = $(obj).attr(name); alert(v1); alert(v2); } /** javascript 通过当前标签属性名,获取属性的值 */ function attrsbyjs(obj){ var v1 = obj.getattribute('name'); var v2 = obj.getattribute('dbname'); alert(v1); alert(v2); } function attrsbuttons(obj){ var v = obj.getattribute('name'); var vv = $(obj).attr(myname); alert(v); alert(vv); } </script> </head> <body> <p> <p style="width: 100px;height: 30px;float:left; margin-left:30px;" name="this is name feild" dbname="oracle1" onclick="attrsbyjs(this)">javascript</p> <p style="width: 100px;height: 30px;float:left; margin-left:30px;" name="this is name feild" dbname="oracle2" onclick="attrsbyjquery(this)">juqery</p> <input type="button" name="abcdeg" myname="this is my name" onclick="attrsbuttons(this)" value="buttons"> </p> </body> </html>
相信看了本文案例你已经掌握了方法,更多精彩请关注其它相关文章!
推荐阅读:
js推拉门效果的实现
vue router+vuex实现后退状态保存
bootstrap实现上传文件时显示进度
以上就是jquery通过当前标签名获取属性的值的详细内容。
