jQuery的一些操作

用prop('属性')可以获取改属性的值,入判断checkbox是否被选中:

  • $('checkboxid').prop('checked'); //获得返回值 true|false

控制checkbox的选中/未选中状态

  • $('checkboxid').prop('checked', true);//选中该checkbox
  • $('checkboxid').prop('checked', false);//取消该checkbox选中

jQueryAjx:

function ajaxFun() {
   $.ajax( {
         type : 'post',// 提交方式
         dataType : 'json'// 提交数据格式
         data : {  
        'param' : paramVal
      }, url : "../xxx/xxx.do", success : function (data) { var json = eval( "(" + data + ")" ); //格式化JSON }, failure : function (data) {//访问失败后操作 // error to do } }); }

 遍历查找选择列表中选中的值

$("#id option:selected").each(function(){
   $("#id2").append("<option value='"+$(this).val()+"'>"+ $(this).text() +"</option>");
    $(this).remove();
});

用了半天的attr都不可以,用prop就可以了

$("#inOnPorts p").each(function(i, r){
        $("#inOnPorts p:eq("+i+") input:eq(1)").prop('checked',true)//窗口默认选中关闭
});
   $("#outOnPorts p").each(function(i, r){
        $("#outOnPorts p:eq("+i+") input:eq(1)").prop('checked',true)//窗口默认选中关闭
});

Checkbox

$(function(){
    $('#chooseall').change(function(){
        if($(this).is(':checked')){
            $('table input[type="checkbox"]').each(function(){
                $(this).prop('checked',true);
            });
        }else{
            $('table input[type="checkbox"]').each(function(){
                $(this).prop('checked', false);
            });
        }
    });

    $('tr').first().nextAll().on('click',function(){
        if($(this).children().first().children().is(':checked')){
            $(this).children().first().children().prop('checked', false);
        }else{
            $(this).children().first().children().prop('checked', true);
        }
    });

});

jQuery重置表单方法

$('#id')[0].reset();

jQuery通过一个对象查找下级

$('#id').children('option');

表格单击事件事件

$('table tbody tr').on('click',function(){
      if($(this).children().first().children().is(':checked')){
          $(this).children().first().children().prop('checked', false);
        }else{
           $(this).children().first().children().prop('checked', true);
      }
 });

密码框监听键盘  键入enter调用登录方法

$(function() {
    $('html').keydown(function(e) {
        if (e.keyCode == 13) {
            LoginResponse();
        }
    });
    var un = $.cookie("username");
    var pwd = $.cookie("password");
    if (un != null && un != "" && un != "null") {
        $("#logUsername").val(un);
    }
    if (pwd != null && pwd != "" && pwd != "null") {
        $("#logPassword").val(pwd);
        $("#remember_me").attr("checked", "checked");
    }
});

获取服务器根目录路径

function download(){ //这是一个下载TOMCAT目录下文件的方法
  window.iframe.location.href="${pageContext.request.contextPath}/resources/x.exe";
}
原文地址:https://www.cnblogs.com/timjames/p/8267186.html