【问题标题】:Need to remove a <br> with JS/CSS需要使用 JS/CSS 删除 <br>
【发布时间】:2013-02-11 16:12:58
【问题描述】:

这是我遇到问题的代码

<script type="text/javascript">

    //<![CDATA[

        $('#blocked_file_extensions').popover({
      'placement': 'bottom',
      "title": "Blocked Extensions",
      "content": "These filetypes will be blocked:`<br>` exe, vbs, pif, scr, bat, cmd, com, cpl, mp3, avi"
    });

    //]]>
    </script>

在这句话“这些文件类型将被阻止:”之后,您会注意到一个&lt;br&gt; 标签。我正在尝试使用 JS 删除&lt;br&gt;,但我似乎无法定位它。我无权访问这部分代码,我只能使用 JS 或 CSS 来更改/删除项目。

我尝试了一些删除和替换功能,但都没有成功。

谢谢。

【问题讨论】:

  • 什么插件提供了.popover() jQuery 扩展?此插件生成的标记是定位&lt;br&gt;所必需的。
  • 内容呈现后,使用浏览器的检查器查看它在 DOM 中的位置。这应该可以帮助您定位元素。

标签: jquery twitter-bootstrap popover


【解决方案1】:

我会看看尝试覆盖您的 js 代码中的选项。之前没用过popover,不过according to the docs you can do something like this

$("#blocked_file_extensions").popover(
    'setOption'
    , 'content'
    , "These filetypes will be blocked: exe, vbs, pif, scr, bat, cmd, com, cpl, mp3, avi"
);

【讨论】:

    【解决方案2】:

    你似乎在使用twitter bootstrap .popover

    您可以销毁弹出框并使用您想要的选项重新定义它..

    <script type="text/javascript">
    //<![CDATA[
    
    $('#blocked_file_extensions').popover('destroy');
    $('#blocked_file_extensions').popover({
          'placement': 'bottom',
          "title": "Blocked Extensions",
          "content": "whatever content you want ..."
        });
    
    //]]>
    </script>
    

    【讨论】:

      【解决方案3】:

      您将如何解决这个问题...

      从原始脚本中创建修改后的脚本并删除原始脚本。

      代码

      <script type="text/javascript">
          function fixScript() {
              // Get all the scripts in the page
              var scripts = document.getElementsByTagName( 'script' );
      
              for(var i = 0; i < scripts.length; i++) {
                  // Find the script we need
                  if(scripts[i].childNodes[0] != undefined) {
                      if(scripts[i].childNodes[0].textContent.indexOf("<br>") !== -1) {
                          // Get the code from the script
                          newData = scripts[i].childNodes[0].textContent.replace("<br>", "");
      
                          // Remove the old script
                          scripts[i].parentNode.removeChild(scripts[i]);
      
                          // Create a new script with fixed data
                          var s1 = document.createElement("script");
                          s1.type = "text/javascript"; 
                          s1.textContent = newData;
                          var s = document.getElementsByTagName("script")[0];
                          s.parentNode.insertBefore(s1, s);
      
                          // Stop
                          break;
                      }
                  }
              }   
          }
      </script>
      

      输出

      <script type="text/javascript">
          //<![CDATA[
      
              $('#blocked_file_extensions').popover({
            'placement': 'bottom',
            "title": "Blocked Extensions",
            "content": "These filetypes will be blocked:`` exe, vbs, pif, scr, bat, cmd, com, cpl, mp3, avi"
          });
      
          //]]>
      </script>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-05-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多