Home > Web Front-end > JS Tutorial > body text

js and jquery get the attribute value in the html tag through this

一个新手
Release: 2017-09-30 09:35:59
Original
1899 people have browsed it


<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(&#39;name&#39;);                
            var v2 = obj.getAttribute(&#39;dbname&#39;);
                alert(v1);
                alert(v2);
            }            
            function attrsButtons(obj){                
            var v = obj.getAttribute(&#39;name&#39;);                
            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>
Copy after login

The above is the detailed content of js and jquery get the attribute value in the html tag through this. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!