您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息
免费发信息
三六零分类信息网 > 大庆分类信息网,免费分类信息发布

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

2024/4/4 2:15:06发布12次查看
<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标签中的属性值 的详细内容。
大庆分类信息网,免费分类信息发布

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录