Jquery 使用

  1.  Jquery动态添加元素添加绑定事件javascript

    Jquery append 等动态添加元素不能直接绑定事件,须要使用on,例如html

  2. <html>
    <head>
        <script type="text/javascript" src="jquery-1.11.0.min.js"></script>
        <script type="text/javascript">
        $(document).ready(function() {
            $("#add").click(function(){
    	   $("#main").append('<input type="text" value="" name="a2" class="a2" />');
    	});
    			
    	$(document).on("change",".a2",function(e){
    		alert($(this).val());
    	});
        });
        </script>
    </head>
    
    <body>
    	<div id="main" style="width:300px; height:100px;border:1px solid red">
    	</div>
            <input type="button" value="添加" id="add" />
    </body>
    
    </html>
  3. 获取高度宽度java

    http://code.jquery.com/jquery-1.4.1.js
    jquery

    $(window).height()  -- 获取浏览器当前窗口可视区域高度浏览器

    $(document).height()  --  获取浏览器当前窗口文档高度闭包

    $(document.body).height()  -- 获取浏览器当前窗口文档body的高度app

    $(document.body).outerHeight(true)  -- 获取浏览器当前窗口可视区域宽度this

  4. 获取select标签值和文本spa

    $("#pcode option:selected").val()  -- 获取选择值code

    $("#pcode option:selected").text()   -- 获取选择文本

  5. 判断字符串空

    if(yj == null || yj == undefined || yj == ''){}

  6. jquery闭包

    (function($){

    })(jQuery);

  7. 阻止表单提交

               $("#_form1").submit(function(e){

                      e.preventDefault();

                      alert("表单阻止提交了");

               });

  8. 验证表单后提交

    $("#_form1").submit(function(){  

        if(须要提交时){  

           $("button[type=submit]").attr("disabled","true");    -- 避免重复提交

            return true;  

        }else(不须要提交时){  

            return false;  

        }  

    });  

相关文章
相关标签/搜索