在特定位置插入li元素

时间:2018-01-10 12:15:03

标签: jquery

我有一个已填充的项目列表,我需要将特定的li元素添加到我通过添加以下内容实现的特定位置

(.*)

我在另一个填充列表的函数中调用了这个函数。

function test() {
  $('#navbar-collapse-menu li:eq(0)').after('<li style="background:orange">Hello</li>') //this adds it to the position i want.
}

function getNestedLists(source, debpth) {
    test();
    var children = $(source).children('li');

    var nestedlist = $('<ul></ul>');

    if (children && children.length > 0) {

        getLinks(nestedlist, children, ++debpth);
    }

    return nestedlist.children('li').length > 0 ? nestedlist : null;

}

问题是,当我进入test()函数时,它会被多次调用。如果我在函数外部调用它它什么都不做。我怎样才能更好地构造它?这就是它的作用:

  • 主页
  • 你好//这是插入的内容
  • 你好
  • 你好
  • 你好
  • 你好
  • 你好
  • 你好
  • TAB1
  • TAB2

我只希望hello li出现如下

  • 主页
  • 你好
  • TAB1
  • TAB2

1 个答案:

答案 0 :(得分:1)

而不是在任何其他函数中调用RROR TypeError: Cannot set property 'message' of undefined at AppComponent.ngAfterViewInit (app.component.ts:88) 而不是单独调用它。

    Dim oGraphics As Graphics = Graphics.FromImage(oBitmap)
    Dim att As New ImageAttributes  'declare an ImageAttributes to use it when drawing'
    Dim m As New ColorMatrix  'declare a ColorMatrix'
    m.Matrix33 = 0.5 ' set Matrix33 to 0.5, which represents the opacity. so the drawing will be semi-trasparent.
    att.SetColorMatrix(m)   'Setting this ColorMatrix to the ImageAttributes.'
    For x = -1 To BlurSize  'drawing the image on it self, but not in the same coordinates, in a way that every pixel will be drawn on the pixels arround it.'
        For y = -1 To BlurSize
            oGraphics.DrawImage(imagePhoto, New Rectangle(x, y, imagePhoto.Width, imagePhoto.Height), 0, 0, imagePhoto.Width, imagePhoto.Height, GraphicsUnit.Pixel, att) 'Drawing image on it self using out ImageAttributes to draw it semi-transparent.'
        Next
    Next