How to add 'if' to jQuery chain code

拥有回忆 提交于 2019-12-13 02:37:41

问题


I need to replace the 4th line in -

this.menu = $("<ul>")
   .addClass("ui-autocomplete")
   .appendTo(this.document.find(this.options.appendTo || "body")[0])
   .zIndex(this.element.zIndex() + 1)  // !! <- here // !!
   .hide()
   .data("menu");

with the following code -

if (XXX.style.setProperty) {  // IE 9- does not support...
    XXX.style.setProperty ("z-index", (this???.element.zIndex() + 1), "important");
  }
  • How do I merge this code?
  • what is 'XXX' in my case?
  • what is "this" ?

[relates to How to add 'important' to zIndex ]


回答1:


This should do it:

this.menu = $("<ul>")
  .addClass("ui-autocomplete")
  .appendTo(this.document.find(this.options.appendTo || "body")[0])
  .each(function() {
    this.style.cssText+= 'z-index: '+(parseInt($(this).css('z-index'))+1)+' !important';
  })
  .hide()
  .data("menu");


来源:https://stackoverflow.com/questions/30556847/how-to-add-if-to-jquery-chain-code

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!