搜尋
首頁web前端js教程關於jQuery Easyui Treegrid如何實作顯示checkbox功能的實例

本文透過實例程式碼介紹jQuery Easyui Treegrid實作顯示checkbox功能的方法,程式碼簡單易懂,非常不錯,具有參考借鏡價值,需要的朋友參考下吧

下面透過本文給大家介紹下圖中的treegrid如何實現?

要求:動態載入;級聯勾選;通關類型判斷顯示包庫/還是鏡像(列有所不同,鏡像共4列),勾選一個複選框,後面的複選框變成不可勾選狀態。

下面是具體程式碼:

1,初始化treegrid,(其中有幾個type列,是由後台人員提供的字段名,雖然我也不想弄一堆type...汗)


var root = 20543;
   //初始化产品树
   function InitProductTreeGrid(rootid) {
    var type = &#39;<%=Controler.ProductType%>&#39;;
   var ishowPack = true;
   var ishowMirro = true;
   //1,包库;2,镜像
   if (type == &#39;1&#39;) {
    ishowPack = false;
    ishowMirro = true;
   } else {
    ishowPack = true;
    ishowMirro = false;
   };
   $(&#39;#tt_Product&#39;).treegrid({
    url: &#39;../Handlers/Contract_ProductHandler.ashx&#39;,
    queryParams: {
     handlertype: "InitProductTreeGrid",
     ContractId: $(&#39;#ContractId&#39;).val(),
     CatalogId: rootid,
     pindex: $(&#39;#pindex&#39;).val()
    },
    idField: &#39;id&#39;,
    width: 930,
    treeField: &#39;CatalogName&#39;,
    fitColumns: true, //宽度自适应窗口
    rownumbers: false, //是否加行号
    singleSelect: true,
    scrollbarSize: 0,  //去除滚动条,否则右边最后一列会自动多处一块
    columns: [[
     { title: &#39;产品列表&#39;, field: &#39;CatalogName&#39;, width: 210 },
     { title: &#39;产品ID&#39;, field: &#39;CatalogId&#39;, hidden: true },
     { title: &#39;父产品ID&#39;, field: &#39;ParentId&#39;, hidden: true },
     { title: &#39;父产品名称&#39;, field: &#39;ParentName&#39;, hidden: true },
     { title: &#39;产品类型&#39;, field: &#39;ProductType&#39;, hidden: true },
     { title: &#39;是否为子节点&#39;, field: &#39;isLeaf&#39;, hidden: true }, //备注:(1,是;0,否)
     { title: &#39;是否为父节点&#39;, field: &#39;isParent&#39;, hidden: true },
     { title: &#39;IsChecked&#39;, field: &#39;IsCheck&#39;, hidden: true },
     { title: &#39;CurrentYearPrices&#39;, field: &#39;type1&#39;, hidden: true },
     { title: &#39;MirrorCurrentYearPrices&#39;, field: &#39;type3&#39;, hidden: true },
     { title: &#39;MirrorEarlyPrices&#39;, field: &#39;type4&#39;, hidden: true },
     { title: &#39;MirrorPrevious3YearPrices&#39;, field: &#39;type5&#39;, hidden: true },
     {
      field: &#39;CurrentYearPrices&#39;, title: &#39;当前价格&#39;, width: 200, hidden: ishowPack,
      formatter: function (value, rec, index) {
       var d = &#39;<input type="checkbox" name="CurrentYearPrices" catalogid="&#39; + rec.CatalogId + &#39;" &#39; + (rec.type1 == &#39;True&#39; ? &#39;checked="checked"&#39; : &#39;&#39;) + &#39; id="CurrentYearPrices&#39; + rec.CatalogId + &#39;" onclick="showProductTree(this,\&#39;CurrentYearPrices\&#39;,&#39; + rec.CatalogId + &#39;,&#39; + rec.isParent + &#39;);" parent="CurrentYearPrices&#39; + rec.ParentId + &#39;" isparent="&#39; + rec.isParent + &#39;" value="&#39; + value + &#39;" />  &#39; + (value != 0 ? value.substr(0, value.length - 2) : &#39;0.00&#39;);

       return d;
      }
     },
     {
      field: &#39;MirrorCurrentYearPrices&#39;, title: &#39;当前价格&#39;, width: 200, hidden: ishowMirro,
      formatter: function (value, rec, index) {
       var d = &#39;<input type="checkbox" name="MirrorCurrentYearPrices" catalogid="&#39; + rec.CatalogId + &#39;" &#39; + (rec.type3 == &#39;True&#39; ? &#39;checked="checked"&#39; : &#39;&#39;) + &#39; id="MirrorCurrentYearPrices&#39; + rec.CatalogId + &#39;" onclick="showProductTree(this,\&#39;MirrorCurrentYearPrices\&#39;,&#39; + rec.CatalogId + &#39;,&#39; + rec.isParent + &#39;);" parent="MirrorCurrentYearPrices&#39; + rec.ParentId + &#39;" isparent="&#39; + rec.isParent + &#39;" value="&#39; + value + &#39;" />  &#39; + value.substr(0, value.length - 2);
       //var d = &#39;<span name="CurrentYearMirrorPrice" id="CurrentYearMirrorPrice&#39; + rec.CatalogId + &#39;" class="tree-checkbox tree-checkbox0">&#39; + value + &#39;</span>&#39;;
       return d;
      }
     },
     {
      field: &#39;MirrorPrevious3YearPrices&#39;, title: &#39;前阶段价格&#39;, width: 200, hidden: ishowMirro,
      formatter: function (value, rec, index) {
       var d = &#39;<input type="checkbox" name="MirrorPrevious3YearPrices" catalogid="&#39; + rec.CatalogId + &#39;" &#39; + (rec.type5 == &#39;True&#39; ? &#39;checked="checked"&#39; : &#39;&#39;) + &#39; id="MirrorPrevious3YearPrices&#39; + rec.CatalogId + &#39;" onclick="showProductTree(this,\&#39;MirrorPrevious3YearPrices\&#39;,&#39; + rec.CatalogId + &#39;,&#39; + rec.isParent + &#39;);" parent="MirrorPrevious3YearPrices&#39; + rec.ParentId + &#39;" isparent="&#39; + rec.isParent + &#39;" value="&#39; + value + &#39;" />  &#39; + value.substr(0, value.length - 2);
       return d;
      }
     },
     {
      field: &#39;MirrorEarlyPrices&#39;, title: &#39;早期价格&#39;, width: 200, hidden: ishowMirro,
      formatter: function (value, rec, index) {
       var d = &#39;<input type="checkbox" name="MirrorEarlyPrices" catalogid="&#39; + rec.CatalogId + &#39;" &#39; + (rec.type4 == &#39;True&#39; ? &#39;checked="checked"&#39; : &#39;&#39;) + &#39; id="MirrorEarlyPrices&#39; + rec.CatalogId + &#39;" onclick="showProductTree(this,\&#39;MirrorEarlyPrices\&#39;,&#39; + rec.CatalogId + &#39;,&#39; + rec.isParent + &#39;);" parent="MirrorEarlyPrices&#39; + rec.ParentId + &#39;" isparent="&#39; + rec.isParent + &#39;" value="&#39; + value + &#39;" />  &#39; + value.substr(0, value.length - 2);
       return d;
      }
     },
     {
      field: &#39;type0&#39;, title: &#39;是否赠送&#39;, width: 200,
      formatter: function (value, rec, index) {
       //alert(rec.isPresent);
       var d = &#39;<input type="checkbox" name="IsPresent" catalogid="&#39; + rec.CatalogId + &#39;" &#39; + (rec.type0 == &#39;True&#39; ? &#39;checked="checked"&#39; : &#39;&#39;) + &#39; id="IsPresent&#39; + rec.CatalogId + &#39;" onclick="showProductTree(this,\&#39;IsPresent\&#39;,&#39; + rec.CatalogId + &#39;,&#39; + rec.isParent + &#39;);" parent="IsPresent&#39; + rec.ParentId + &#39;" isparent="&#39; + rec.isParent + &#39;" value="0" />  &#39;;
       return d;
      }
     }
    ]],
    loadFilter: function (data, parentId) {
     //逐层加载
     function setData() {
      var todo = [];
      for (var i = 0; i < data.length; i++) {
       todo.push(data[i]);
      }
      while (todo.length) {
       var node = todo.shift();
       if (node.children) {
        node.state = &#39;closed&#39;;
        node.children1 = node.children;
        node.children = undefined;
        todo = todo.concat(node.children1);
       }
      }
     }
     setData(data);
     var tg = $(this);
     var opts = tg.treegrid(&#39;options&#39;);
     opts.onBeforeExpand = function (row) {
      if (row.children1) {
       tg.treegrid(&#39;append&#39;, {
        parent: row[opts.idField],
        data: row.children1
       });
       row.children1 = undefined;
       tg.treegrid(&#39;expand&#39;, row[opts.idField]);
      }
      return row.children1 == undefined;
     };
     return data;
    },
    onLoadSuccess: function (row, data) {
     //alert(data[0].CatalogId)
     RelativeTreeGridCheck();
    }
   });
  };

2,onLoadSuccess中的RelativeTreeGridCheck()級聯方法


##

var parentcid;
  var ispid;
  var tempid;
  //父节点选中关联子节点选中
  function RelativeTreeGridCheck() {
   var rows = $(&#39;#addProductTbl&#39;).find(&#39;.datagrid-view2 .datagrid-body .datagrid-btable tr&#39;);
   for (var i = 0; i < rows.length; i++) {
    if ($(rows).eq(i).attr(&#39;node-id&#39;) != undefined) {
     parentcid = "";
     ispid = -1;
     tempid = "";
     catalogid = $(rows).eq(i).attr(&#39;node-id&#39;);
     //alert(catalogid);
     var cols = $(rows).eq(i).find(&#39;td&#39;);
     var fields = &#39;&#39;;
     for (var j = 0; j < cols.length; j++) {
      fields = $(cols).eq(j).attr(&#39;field&#39;);
      //alert(&#39;fields:&#39; + fields);
      switch (fields) {
       case &#39;CurrentYearPrices&#39;:
       case &#39;MirrorCurrentYearPrices&#39;:
       case &#39;MirrorPrevious3YearPrices&#39;:
       case &#39;MirrorEarlyPrices&#39;:
       case &#39;type0&#39;:
        if ($(cols).eq(j).find(&#39;p input:checked&#39;).length > 0) {
         parentcid = $(cols).eq(j).parent().find("td[field=&#39;CatalogId&#39;]").find(&#39;p&#39;).html();
         ispid = $(cols).eq(j).parent().find("td[field=&#39;isParent&#39;]").find(&#39;p&#39;).html();
         contractproducttype = $(cols).eq(j).find(&#39;p input&#39;).attr(&#39;name&#39;);
         if (ispid == &#39;1&#39;) {
          //获取checkbox对象
          var obj = $(cols).eq(j).find(&#39;p input:checkbox&#39;);
          //如果父节点选中,自己点也连带选中
          showProductTree(obj, contractproducttype, parentcid, ispid)
         }
        }
        break;
      }
     }
    }
   }
  }
function showProductTree(obj, catalogtype, id, isparent) {
   //alert(id.indexof(&#39;2&#39;));
   if (isparent == 1) {
    //当前节点下包库子节点
    //alert(&#39;$(obj).attr(checked)&#39; + $(obj).attr(&#39;checked&#39;));
    var state = $(obj).attr(&#39;checked&#39;) == undefined ? false : true;
    //alert(&#39;state:&#39;+state+&#39; id:&#39;+id);
    //找出子节点
    var nodes = $(&#39;input[name="&#39; + catalogtype + &#39;"][parent="&#39; + catalogtype + id + &#39;"]&#39;);
    nodes.each(function () {
     //alert(&#39;$(this).attr(checked):&#39; + $(this).attr(&#39;checked&#39;));
     var curobjstate = $(this).attr(&#39;checked&#39;) == undefined ? false : true;
     disabledOthersCatalogType($(this), state, catalogtype)
     //alert(&#39;curobjstate:&#39; + curobjstate + &#39; state:&#39; + state + &#39; id:&#39; + id + &#39; isparent: &#39; + $(this).attr(&#39;isparent&#39;));
     if (curobjstate == state && $(this).attr(&#39;isparent&#39;) == &#39;0&#39;) {
      //alert(&#39;leaf&#39;);
      //如果当前节点的选中状态和父节点不同,并且当前节点不是父节点
      $(this).attr(&#39;checked&#39;, state);
      $(this).prop(&#39;checked&#39;, state);
     } else {
      //alert(&#39;$(this).attr(catalogid)&#39; + $(this).attr(&#39;catalogid&#39;) + &#39;---$(this).attr(isparent)&#39; + $(this).attr(&#39;isparent&#39;));
      $(this).attr(&#39;checked&#39;, state);
      $(this).prop(&#39;checked&#39;, state);
      showProductTree($(this), catalogtype, $(this).attr(&#39;catalogid&#39;), $(this).attr(&#39;isparent&#39;))
     }
     if (state) {
      $(this).removeAttr(&#39;disabled&#39;);
     }
    });
    $(obj).prop(&#39;checked&#39;, state);
    disabledOthersCatalogType($(obj), state, catalogtype)
   } else {
    var state = $(obj).attr(&#39;checked&#39;) == undefined ? false : true;
    //alert(state);
    //alert(catalogtype);
    disabledOthersCatalogType($(obj), state, catalogtype)
    updateParentNodeCheckState($(obj), state, catalogtype)
   }
  }
  //修改其他产品类型的checkbox的只读状态
  function disabledOthersCatalogType(obj, state, catalogtype) {
   $(&#39;input[catalogid="&#39; + $(obj).attr(&#39;catalogid&#39;) + &#39;"]&#39;).each(function () {
    if ($(this).attr(&#39;name&#39;) != catalogtype) {
     if (state) {
      $(this).attr(&#39;disabled&#39;, &#39;disabled&#39;);
     } else {
      $(this).removeAttr(&#39;disabled&#39;);
     }
     $(this).attr(&#39;checked&#39;, false).prop(&#39;checked&#39;, false);
    }
   });
  }
  //查找上一层节点,修改其状态
  function updateParentNodeCheckState(obj, state, catalogtype) {
   var pid = $(obj).attr(&#39;parent&#39;);
   //如果父节点是根节点,则不再执行
   if (pid == catalogtype + root || $(&#39;#&#39; + pid).length == 0) return;
   var parent = $(&#39;#&#39; + pid);
   if (!state) {
    //取消父节点的选中状态
    parent.attr(&#39;checked&#39;, false)
    parent.prop(&#39;checked&#39;, false)
   } else {
    //alert(&#39;pid:&#39;+pid+&#39;---&#39;+$(&#39;input[parent="&#39; + pid + &#39;"]:checked&#39;).length+&#39;------&#39;+$(&#39;input[parent="&#39; + pid + &#39;"]&#39;).length);
    //alert(&#39;checkedLen:&#39; + $(&#39;input[parent="&#39; + pid + &#39;"]:checked&#39;).length + &#39; len:&#39; + $(&#39;input[parent="&#39; + pid + &#39;"]&#39;).length);
    //子节点全部选中
    if ($(&#39;input[parent="&#39; + pid + &#39;"]:checked&#39;).length == $(&#39;input[parent="&#39; + pid + &#39;"]&#39;).length) {
     parent.attr(&#39;checked&#39;, true);
     parent.prop(&#39;checked&#39;, true);
    }
   }
   //修改其他产品类型的checkbox的只读状态
   disabledOthersCatalogType(parent, state, catalogtype)
   //继续查找上一层节点
   updateParentNodeCheckState(parent, state, catalogtype)
  }

3,由於是拼接比較繁雜,在此順便再說一下傳參代碼


//新增产品单击操作处理
  function subAddProduct() { 5    var strJson = &#39;&#39;;
   var selectedvalued = $(&#39;#cbo_selFirstCombbox&#39;).combobox(&#39;getValue&#39;);
   //下拉框选中的value
   selectedvalued = selectedvalued == &#39;&#39; ? &#39;20544&#39; : selectedvalued;
   //
   var ids = &#39;&#39;; 
   var rows = $(&#39;#addProductTbl&#39;).find(&#39;.datagrid-view2 .datagrid-body .datagrid-btable tr&#39;);
   strJson += "[";
   for (var i = 0; i < rows.length; i++) {
    catalogid = -1;
    catalogname = &#39;&#39;;
    productfather = -1;
    contractproducttype = &#39;&#39;;
    quoteprice = -1;
    isfather = -1;
    productfathername = &#39;&#39;;
    if ($(rows).eq(i).attr(&#39;node-id&#39;) != undefined) {
     catalogid = $(rows).eq(i).attr(&#39;node-id&#39;);
     //alert(catalogid);
     var cols = $(rows).eq(i).find(&#39;td&#39;);
     var fields = &#39;&#39;;
     for (var j = 0; j < cols.length; j++) {
      fields = $(cols).eq(j).attr(&#39;field&#39;);
      //alert(&#39;fields:&#39; + fields);
      switch (fields) {
       case &#39;CatalogName&#39;:
        $(cols).eq(j).find(&#39;p span&#39;).each(function (index) {
         if ($(cols).eq(j).find(&#39;p span&#39;).eq(index).hasClass(&#39;tree-title&#39;)) {
          catalogname = $(cols).eq(j).find(&#39;p span&#39;).eq(index).html();
         }
        });
        //alert(catalogname);
        break;
       case &#39;ParentId&#39;:
        productfather = $(cols).eq(j).find(&#39;p&#39;).html();
        break;
       case &#39;IsCheck&#39;:
        //原树选中节点id的获取(不包含修改的id节点),此步骤目的是为了配合后台方法,作用是先删除当前版本下所有树选中的节点,再获取页面中修改后的
        //节点,进行更新操作
        var oldcheck = $(cols).eq(j).find(&#39;p&#39;).html();
        if (oldcheck == &#39;True&#39;) {
         var cid = $(cols).eq(j).parent().find("td[field=&#39;CatalogId&#39;]").find(&#39;p&#39;).html();
         ids += cid + &#39;,&#39;;
         //alert(ids)
        }
        break;
       case &#39;CurrentYearPrices&#39;:
       case &#39;MirrorCurrentYearPrices&#39;:
       case &#39;MirrorPrevious3YearPrices&#39;:
       case &#39;MirrorEarlyPrices&#39;:
       case &#39;type0&#39;:
        if ($(cols).eq(j).find(&#39;p input:checked&#39;).length > 0) {
         isfather = $(cols).eq(j).parent().find("td[field=&#39;isParent&#39;]").find(&#39;p&#39;).html();
         productfathername = $(cols).eq(j).parent().find("td[field=&#39;ParentName&#39;]").find(&#39;p&#39;).html();
         contractproducttype = $(cols).eq(j).find(&#39;p input&#39;).attr(&#39;name&#39;);
         if (contractproducttype == &#39;IsPresent&#39;) {
          var type = &#39;<%=Controler.ProductType%>&#39;;
           contractproducttype = type == &#39;1&#39; ? &#39;CurrentYearPrices&#39; : &#39;MirrorCurrentYearPrices&#39;; //如果类型为镜像,则默认为镜像当年
          //alert($(cols).eq(j).parent().find("td[field=&#39;" + contractproducttype + "&#39;]").find(&#39;p input&#39;).val());
          //quoteprice = 0;
           quoteprice = $(cols).eq(j).parent().find("td[field=&#39;" + contractproducttype + "&#39;]").find(&#39;p input&#39;).val();
           ispresent = 1;
          } else {
           quoteprice = $(cols).eq(j).find(&#39;p input&#39;).val();
           ispresent = 0;
          }
         //alert(&#39;name:&#39; + $(cols).eq(j).find(&#39;p input&#39;).attr(&#39;name&#39;) + &#39; value:&#39; + $(cols).eq(j).find(&#39;p input&#39;).val());
         }
         break;
       }
      }
     //alert(&#39;catalogid:&#39; + catalogid + &#39;--catalogname:&#39; + catalogname + &#39;--productfather:&#39; + productfather + &#39;--contractproducttype:&#39; + contractproducttype + &#39;--quoteprice:&#39; + quoteprice);
      if (catalogid != -1 && catalogname != &#39;&#39; && productfather != -1 && contractproducttype != &#39;&#39; && quoteprice != -1 && productfathername != &#39;&#39;) {
       strJson += "{\"ProductID\":\"" + catalogid + "\",\"ContractProductType\":\"" + contractproducttype + "\",\"ProductFather\":\"" + productfather + "\",\"Productname\":\"" + catalogname + "\",\"Quotedprice\":\"" + quoteprice + "\",\"Oldproduct\":\"" + oldproduct + "\",\"IsPresent\":\"" + ispresent + "\",\"ContractID\":\"" + $(&#39;#ContractId&#39;).val() + "\",\"SelectedID\":\"" + selectedvalued + "\",\"IsParent\":\"" + isfather + "\",\"ProductFatherName\":\"" + productfathername + "\",\"IsNull\":\"0\"},";
      }
     }
    }
   //alert(strJson);
    if (strJson == &#39;[&#39;) {
     strJson = "[{\"ContractID\":\"" + $(&#39;#ContractId&#39;).val() + "\",\"SelectedID\":\"" + selectedvalued + "\",\"IsNull\":\"1\"}]";
    } else {
     strJson = strJson.substr(0, strJson.length - 1);
     strJson += "]";
    }
    ids = ids.substr(0, ids.length - 1);
    subProduct(strJson, ids);
   //alert(rows.length);
   }
   //新增产品提交操作
   function subProduct(strJson, ids) {
    $.post(&#39;../Handlers/Contract_ProductHandler.ashx&#39;, { &#39;handlertype&#39;: &#39;subAddProduct&#39;, &#39;strJson&#39;: strJson, &#39;ids&#39;: ids, &#39;pindex&#39;: $(&#39;#pindex&#39;).val() }, function (responseData) {121      switch (responseData.Status) {
      case "success":
       //成功的操作
       $.messager.alert(&#39;提示&#39;, responseData.Msg);
       $(&#39;#ProductWinTree&#39;).window(&#39;close&#39;);
       //$(&#39;#selFirstCombbox&#39;).val(&#39;6774&#39;);
       $(&#39;#dg_Product&#39;).datagrid(&#39;reload&#39;);
       break;
      case "failed":
       //失败的操作
       $.messager.alert(&#39;提示&#39;, responseData.Msg);
       break;
     }
    }, &#39;json&#39;);
   }

總結

以上是關於jQuery Easyui Treegrid如何實作顯示checkbox功能的實例的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
JavaScript在行動中:現實世界中的示例和項目JavaScript在行動中:現實世界中的示例和項目Apr 19, 2025 am 12:13 AM

JavaScript在現實世界中的應用包括前端和後端開發。 1)通過構建TODO列表應用展示前端應用,涉及DOM操作和事件處理。 2)通過Node.js和Express構建RESTfulAPI展示後端應用。

JavaScript和Web:核心功能和用例JavaScript和Web:核心功能和用例Apr 18, 2025 am 12:19 AM

JavaScript在Web開發中的主要用途包括客戶端交互、表單驗證和異步通信。 1)通過DOM操作實現動態內容更新和用戶交互;2)在用戶提交數據前進行客戶端驗證,提高用戶體驗;3)通過AJAX技術實現與服務器的無刷新通信。

了解JavaScript引擎:實施詳細信息了解JavaScript引擎:實施詳細信息Apr 17, 2025 am 12:05 AM

理解JavaScript引擎內部工作原理對開發者重要,因為它能幫助編寫更高效的代碼並理解性能瓶頸和優化策略。 1)引擎的工作流程包括解析、編譯和執行三個階段;2)執行過程中,引擎會進行動態優化,如內聯緩存和隱藏類;3)最佳實踐包括避免全局變量、優化循環、使用const和let,以及避免過度使用閉包。

Python vs. JavaScript:學習曲線和易用性Python vs. JavaScript:學習曲線和易用性Apr 16, 2025 am 12:12 AM

Python更適合初學者,學習曲線平緩,語法簡潔;JavaScript適合前端開發,學習曲線較陡,語法靈活。 1.Python語法直觀,適用於數據科學和後端開發。 2.JavaScript靈活,廣泛用於前端和服務器端編程。

Python vs. JavaScript:社區,圖書館和資源Python vs. JavaScript:社區,圖書館和資源Apr 15, 2025 am 12:16 AM

Python和JavaScript在社區、庫和資源方面的對比各有優劣。 1)Python社區友好,適合初學者,但前端開發資源不如JavaScript豐富。 2)Python在數據科學和機器學習庫方面強大,JavaScript則在前端開發庫和框架上更勝一籌。 3)兩者的學習資源都豐富,但Python適合從官方文檔開始,JavaScript則以MDNWebDocs為佳。選擇應基於項目需求和個人興趣。

從C/C到JavaScript:所有工作方式從C/C到JavaScript:所有工作方式Apr 14, 2025 am 12:05 AM

從C/C 轉向JavaScript需要適應動態類型、垃圾回收和異步編程等特點。 1)C/C 是靜態類型語言,需手動管理內存,而JavaScript是動態類型,垃圾回收自動處理。 2)C/C 需編譯成機器碼,JavaScript則為解釋型語言。 3)JavaScript引入閉包、原型鍊和Promise等概念,增強了靈活性和異步編程能力。

JavaScript引擎:比較實施JavaScript引擎:比較實施Apr 13, 2025 am 12:05 AM

不同JavaScript引擎在解析和執行JavaScript代碼時,效果會有所不同,因為每個引擎的實現原理和優化策略各有差異。 1.詞法分析:將源碼轉換為詞法單元。 2.語法分析:生成抽象語法樹。 3.優化和編譯:通過JIT編譯器生成機器碼。 4.執行:運行機器碼。 V8引擎通過即時編譯和隱藏類優化,SpiderMonkey使用類型推斷系統,導致在相同代碼上的性能表現不同。

超越瀏覽器:現實世界中的JavaScript超越瀏覽器:現實世界中的JavaScriptApr 12, 2025 am 12:06 AM

JavaScript在現實世界中的應用包括服務器端編程、移動應用開發和物聯網控制:1.通過Node.js實現服務器端編程,適用於高並發請求處理。 2.通過ReactNative進行移動應用開發,支持跨平台部署。 3.通過Johnny-Five庫用於物聯網設備控制,適用於硬件交互。

See all articles

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

AI Hentai Generator

AI Hentai Generator

免費產生 AI 無盡。

熱工具

SublimeText3 英文版

SublimeText3 英文版

推薦:為Win版本,支援程式碼提示!

Dreamweaver Mac版

Dreamweaver Mac版

視覺化網頁開發工具

禪工作室 13.0.1

禪工作室 13.0.1

強大的PHP整合開發環境

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)

EditPlus 中文破解版

EditPlus 中文破解版

體積小,語法高亮,不支援程式碼提示功能