我该如何用伪代码编写这些jquery方法?

时间:2018-12-12 23:30:06

标签: jquery pseudocode

我正在努力了解如何用伪代码编写这些代码。

  function makeHeader(label, width){
      //make the header element
      newHeader = $("<th/> <br/>")
        .html(label)
        .addClass("col-sm-"+width)
      return newHeader
  }

我指的是.html和.addClass部分,我不太了解如何用伪代码编写。

1 个答案:

答案 0 :(得分:0)

要写这个:

function makeHeader(label, width){
    newHeader = $("<th/> <br/>").html(label).addClass("col-sm-"+width)
    return newHeader
}

在伪代码中,您可以仅查看每个语句并查看其作用,如果需要帮助,请查看jQuery documentation。但这是完整的伪代码:

Define a function makeHeader, which takes parameters label and width
    Define a variable newHeader, which is HTML markup <th></th><br/>.
        Set the innerHTML property of the element contained in newHeader to the label parameter passed to the function
        Add a class to the element contained in newHeader. The class added will be col-sm- followed by the width parameter passed to the function
    Return the newHeader variable from the function