Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript和jQuery的变量_Javascript_Jquery_Syntax - Fatal编程技术网

Javascript和jQuery的变量

Javascript和jQuery的变量,javascript,jquery,syntax,Javascript,Jquery,Syntax,请在下面的3行代码中解释headvar发生了什么(以及它的使用),而不是(在我有限的理解下)在这一过程中跌跌撞撞 <script type="text/javascript"> var head = $("thead#tHead1").clone().removeAttr("class"); $(head).find("#hRow2").remove(); head = $(head).wrap("<thead>").parent().html(); va

请在下面的3行代码中解释
head
var发生了什么(以及它的使用),而不是(在我有限的理解下)在这一过程中跌跌撞撞

<script type="text/javascript">
  var head = $("thead#tHead1").clone().removeAttr("class");
  $(head).find("#hRow2").remove();
  head = $(head).wrap("<thead>").parent().html();

var head=$(“thead#tHead1”).clone().removeAttr(“类”);
$(head).find(“#hRow2”).remove();
head=$(head.wrap(“”.parent().html();
编辑 在第1行设置
head=
后,在第2行代码上使用
$(head)
的意义是什么

请参阅我学到的答案。

//找到一个元素,复制它,并删除它的类
// Find an element, make a copy of it, and remove it's class
var head = $("thead#tHead1").clone().removeAttr("class");

// Within the cloned element (not on the DOM yet),
// Find an element within and then remove that found element.
$(head).find("#hRow2").remove();

// Wrap the cloned element in another element, giving it a parent.
// Traverse to that parent and return it's html content
head = $(head).wrap("<thead>").parent().html();
var head=$(“thead#tHead1”).clone().removeAttr(“类”); //在克隆的元素中(尚未在DOM上), //在中查找元素,然后删除找到的元素。 $(head).find(“#hRow2”).remove(); //将克隆的元素包装到另一个元素中,给它一个父元素。 //遍历到该父对象并返回其html内容 head=$(head.wrap(“”.parent().html();
注意这里不需要
$(head)
。那可以是
head
。您不需要将元素转换为jQuery包装的对象,因为它应该已经是一个对象了


而且,这是一个糟糕的代码。这是对DOM的一个笨拙的攻击,它应该做什么就做什么。相反,您应该使用某种类型的模板引擎根据需要根据一些输入数据生成新的DOM片段。

//找到一个元素,复制它,并删除它的类
var head=$(“thead#tHead1”).clone().removeAttr(“类”);
//在克隆的元素中(尚未在DOM上),
//在中查找元素,然后删除找到的元素。
$(head).find(“#hRow2”).remove();
//将克隆的元素包装到另一个元素中,给它一个父元素。
//遍历到该父对象并返回其html内容
head=$(head.wrap(“”.parent().html();
注意这里不需要
$(head)
。那可以是
head
。您不需要将元素转换为jQuery包装的对象,因为它应该已经是一个对象了



而且,这是一个糟糕的代码。这是对DOM的一个笨拙的攻击,它应该做什么就做什么。相反,您应该使用某种类型的模板引擎,根据需要根据一些输入数据生成新的DOM片段。

我将向您介绍以下内容:

  • 一个开始的
    标记,顺便说一下,它不需要
    类型
    属性

  • 查找id为AD1的
    元素,复制包含子节点的元素,并从新元素中删除
    属性,然后将新元素分配给
    变量

  • 删除id为
    hRow2
    的元素,该元素位于我们先前创建的元素内部

  • 将前面创建的元素包装在
    thead
    元素中,并重新分配
    head
    变量,使其等于该“”元素的innerHTML


  • 我将带您浏览以下内容:

  • 一个开始的
    标记,顺便说一下,它不需要
    类型
    属性

  • 查找id为AD1的
    元素,复制包含子节点的元素,并从新元素中删除
    属性,然后将新元素分配给
    变量

  • 删除id为
    hRow2
    的元素,该元素位于我们先前创建的元素内部

  • 将前面创建的元素包装在
    thead
    元素中,并重新分配
    head
    变量,使其等于该“”元素的innerHTML


  • 从评论和进一步的研究中,我认为这可以更好地写成:

    var head = $("#tHead1").clone().removeAttr("class");   // clean & clone the head  
    head.find("#hRow2").remove();                          // remove 2nd row
    head = head[0].outerHTML;                              // get 'only' the desired html
    
    为了回答我自己的问题,(我不确定术语),最后一个
    头=
    在这种情况下是必要的,不显示
    [object]
    。它不指定对象,而是指定所需的HTML(标题行),以便稍后在代码中使用
    console.log(head)
    揭示了这一课。我也不确定为什么第1行和第2行不能被链接,所以这是我能做到的最干净的


    此练习的更高目的是在打印之前将一个大表拆分为单独的(45行)表,在后续页面上仅显示3个标题行中的2个,并且不联系服务器或重新加载页面。我的方法是在第n行中添加一个end-of-page类,完成上述操作,然后在该行后面追加()新的表和标题

    从评论和进一步的研究中,我认为这可以更好地写成:

    var head = $("#tHead1").clone().removeAttr("class");   // clean & clone the head  
    head.find("#hRow2").remove();                          // remove 2nd row
    head = head[0].outerHTML;                              // get 'only' the desired html
    
    为了回答我自己的问题,(我不确定术语),最后一个
    头=
    在这种情况下是必要的,不显示
    [object]
    。它不指定对象,而是指定所需的HTML(标题行),以便稍后在代码中使用
    console.log(head)
    揭示了这一课。我也不确定为什么第1行和第2行不能被链接,所以这是我能做到的最干净的


    此练习的更高目的是在打印之前将一个大表拆分为单独的(45行)表,在后续页面上仅显示3个标题行中的2个,并且不联系服务器或重新加载页面。我的方法是在第n行中添加一个end-of-page类,完成上述操作,然后在该行后面追加()新的表和标题

    对。它将引用第2行中的克隆头元素。第三行的
    $(head)
    也一样。@nhahtdh请检查编辑。“用法”问题不清楚。这是一些糟糕的代码<代码>元素不属于其他
    元素。是。它将引用第2行中的克隆头元素。第三行的
    $(head)
    也一样。@nhahtdh请检查编辑。“用法”问题不清楚。这是一些糟糕的代码<代码>元素