zoukankan      html  css  js  c++  java
  • web 前端遇到的问题

    前端小白一枚,经常遇到一些小问题,但是解决完吧,又记不住,哎,好记性不如烂笔头咯

    1. 如何在js代码中设置checkbox选中?

    $("#select").attr('checked',true);  //这个貌似时灵时不灵??待解决

    2. 判断checkBox是否选中?

    $("#select").is(':checked');  // $("#select).val()  或者 $("#select").attr('checked') 貌似是行不通

    //关于实现checkbox单选

    $(':checkbox[name="group_name"]').each(function(){
                $(this).click(function(){
                    if($(this).is(':checked')){
                        $(':checkbox[name="group_name"]').removeAttr('checked');
                        $(this).prop('checked',true);
                    }
    });
    });

     

    3. 关于js数组push,push了一个Object,但是发现不能push成功?? 

    4. 关于js中的回调函数

      我理解的就是在执行完自身方法之后执行参数中传入的方法。  

    function f1(ops,callback){
        alert('f1');
         if (typeof callback === "function"){
           
                callback(ops); 
            }
    }
    
    function f2(){
       alert('f2');    
       if(arguments.length>0){
           console.log(arguments[0]);
        }    
        
    }
    
    f1({'name':'kkw'},f2);  //执行调用

    大概就是这样吧,有待进一步研究。

    5. 关于echarts中click事件重复执行的解决方案,在绑定click事件前关闭click事件,防止重复绑定:

    myChart.off('click');

     6. 关于同一页面多个ajax异步加载时,可使用ajaxSetup+layer.load 方式做到数据加载的小圈,so easy

    var index;
    var hasLoad;
    function loadAction(i){    //i是指外部ajax请求的个数
        index = i;
        hasLoad = -1;
        $.ajaxSetup({
              contentType:"application/x-www-form-urlencoded;charset=utf-8",
              beforeSend : function(){
                  if(hasLoad<=-1){
                      hasLoad = layer.load(2);
                  }
              },
              complete: function(XMLHttpRequest,textStatus) {
                  index --;
                  if(index == 0){
                      layer.close(hasLoad);
                      hasLoad = -1;
                  }
             }
         });
    }

     7. 获取select组件中选中的option

    var options = $("#selectid option:selected");
  • 相关阅读:
    hive 调优
    nohup
    安装ElasticSearch 6.1.1 head插件
    101. Symmetric Tree
    67. Add Binary
    70. Climbing Stairs
    896. Monotonic Array
    66. Plus One
    27. Remove Element
    Apache Tomcat文件包含漏洞风险大,威胁全球约8万台服务器
  • 原文地址:https://www.cnblogs.com/FancyLian/p/7435327.html
Copyright © 2011-2022 走看看