zoukankan      html  css  js  c++  java
  • 避免编写解决"不存在"问题的代码

    避免编写解决"不存在"问题的代码。即在项目开发中仅仅只编写与你问题相关的代码,而不是刻意添加与问题不相关的代码。如果你认为所做的代码能达到通用的层次,则建议将它封装到工具类中,而不是散列到各个业务文件中。这样可以更好的维护代码和提高重用性。

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        <script src="jquery.js" type="text/javascript"></script>
        <script>
        (function(window){        
            var jS = function () { };
            jS.prototype = {
                //根据ID获取对应的元素
                get: function (id, tag) {
                    if (tag == undefined) return $("#" + id);
                    switch (tag.toLowerCase()) {
                        case "drop":
                            return $("select[name$=" + id + "]");
                        case "radio":
                            return $("input[name$=" + id + "]");
                        case "check":
                        case "table":
                            return $("table[id$=" + id + "]");
                        case "input":
                            return $("input[id$=" + id + "]");
                        case "link":
                            return $("a[id$=" + id + "]");
                    }
                },
                //获取一组ID指定的元素
                gets: function (ids, tag) {
                    var arr = ids; //ids可为数组或以逗号分隔的ID列表
                    if (!(ids instanceof Array)) {
                        arr = ids.split(',');
                    }
                    var elems = oa.dom.get(arr[0], tag);
                    for (var i = 1; i < arr.length; i++) {
                        elems = elems.add(oa.dom.get(arr[i], tag));
                    }
                    return elems;
                }
            };
            window.S = new jS();
            })(window)
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:TextBox ID="TextBox1" Text="Text" runat="server"></asp:TextBox>
            <script type="text/javascript">
                document.write($(S.get("TextBox1", "input")).val());//结果 Text
            </script>
        </div>
        </form>
    </body>
    </html>

     附件下载

  • 相关阅读:
    Larval API 跨域问题解决
    php常用接口
    phpstudy+nigix+larval伪静态配置
    js、jquery让滚动条到底部
    JS 数组转json和json转数组
    python 基础(十七)内置函数
    python 基础(十六)生成器用法举例
    python 基础(十五)生成器
    python 基础(十四)装饰器
    python基础(十三)模块的定义、导入
  • 原文地址:https://www.cnblogs.com/sntetwt/p/2992900.html
Copyright © 2011-2022 走看看