bootstrap-maxlength总是在顶部

时间:2015-12-09 13:43:33

标签: jquery css twitter-bootstrap twitter-bootstrap-3 bootstrap-modal

使用bootstrap-maxlength插件:https://github.com/mimo84/bootstrap-maxlength

它工作得很好,但是当一个引导模式弹出时,这个插件的剩余字符标签仍然显示在模态上。

提前谢谢。

--- ---编辑

main.js

$(document).ready(function){
   //textareaID is the element where i want to wrap charactercounter
   $('#textareaID').maxlength({
      showOnReady: false,
      alwaysShow: true,
      threshold: 10,
      warningClass: 'label label-success',
      limitReachedClass: 'label label-important label-danger',
      separator: ' / ',
      preText: '',
      postText: '',
      showMaxLength: true,
      placement: 'top',
      message: 'Remaining chars: %charsRemaining%',
      showCharsTyped: true,
      validate: true,
      utf8: false,
      appendToParent: true,
      twoCharLinebreak: true,
      customMaxAttribute: null,
      allowOverMax: false
   });
}

此外,该插件会生成html,如:

<span class="bootstrap-maxlength label label-success" style="display: block; position: absolute; white-space: nowrap; z-index: 1099; top: -22px; left: 395.453px;">Remaining chars: 989</span>

1 个答案:

答案 0 :(得分:2)

此元素显示在name1=(char*)malloc((strlen(argv[2])+1)*sizeof(char)); name2=(char*)malloc(1+(strlen(name1))*sizeof(char)); strcpy(name1, argv[2]); strncpy(name2, name1, strlen(name1)-3); strcat(name2, "pts"); 上的原因是因为其modal属性。在z-index源代码中,列出了为公共元素定义的Bootstrap个属性:

z-index

@zindex-navbar: 1000; @zindex-dropdown: 1000; @zindex-popover: 1060; @zindex-tooltip: 1070; @zindex-navbar-fixed: 1030; @zindex-modal-background: 1049; /* Blurry Modal back-drop */ @zindex-modal: 1050; /* Actual Modal */ 的源代码中,我们可以看到以下代码:

maxlength.js

如您所见,if (!maxLengthIndicator) { maxLengthIndicator = $('<span class="bootstrap-maxlength"></span>').css({ display: 'none', position: 'absolute', whiteSpace: 'nowrap', zIndex: 1099 // Notice here, z-index is higher than the Bootstrap modal }).html(maxlengthContent); } 1099大于z-index的1049和1050.如果您不希望它显示在{{1}上方},您可以更改modal并更改此生成元素的modal,或者在第一次调用bootstrap-maxlength.js后使用jQuery更改它:

z-index

最后,.maxlength({ })页面显示:

  

指示标记会在聚焦于元素时显示,并在焦点丢失时消失。

对我来说,这意味着您的问题不应该成为一个问题,因为$('.bootstrap-maxlength').css({ z-index: 1040 }); 出现会引发您github的失焦,但我不会有任何方法可以测试当前。话虽如此,您可以在模式打开时在modal上触发<textarea>,这应隐藏插件生成的maxlength blur()

$("#textareaID")

希望这能为您提供一些见解。

相关问题