Home >Web Front-end >JS Tutorial >JQUERY gets the value of the attribute through the current tag name
This time I will bring you JQUERYGet the value of the attribute through the current tag name. What are the precautions for JQUERY to get the attribute value through the current tag name? , the following is a practical case, let’s take a look.
No more nonsense, the specific code is as follows:
<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>
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the PHP Chinese website !
Recommended reading:
Implementation of js sliding door effect
Vue Router Vuex implements backward state saving
BootStrap implements display progress when uploading files
The above is the detailed content of JQUERY gets the value of the attribute through the current tag name. For more information, please follow other related articles on the PHP Chinese website!