您好,欢迎访问一九零五行业门户网

js和jquery通过this获取html标签中的属性值

<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和jquery通过this获取html标签中的属性值 的详细内容。
其它类似信息

推荐信息