zoukankan      html  css  js  c++  java
  • 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");
              var v3 = $(obj).attr('id'); alert(v1); //"oracle1" alert(v2); //"this is name feild"
             alert(v3); //'123' }
    /** 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> <div> <div style=" 100px;height: 30px;float:left; margin-left:30px;" name="this is name feild" id='123' dbname="oracle1" onclick="attrsByJs(this)">JavaScript</div> <div style=" 100px;height: 30px;float:left; margin-left:30px;" name="this is name feild" dbname="oracle2" onclick="attrsByJquery(this)">Juqery</div> <input type="button" name="abcdeg" myname="this is my name" onclick="attrsButtons(this)" value="buttons"> </div> </body> </html>

    原文地址:https://www.cnblogs.com/duck-ifox/p/5857545.html

  • 相关阅读:
    MySQL数据库索引相关
    springMVC架构说明
    @responseBody注解的使用
    springMVC配置
    17_10_31 ./ ../ / ~/
    Nginx的简单操作
    MySQL中sql语句的优化
    Mac下Redis的简单操作
    github下载与安装(windows版)
    结合工程实践选题调研分析3个同类软件产品
  • 原文地址:https://www.cnblogs.com/zxyun/p/10475239.html
Copyright © 2011-2022 走看看