【问题标题】:bbcode doesn't work when i add online jquery library in footer当我在页脚中添加在线 jquery 库时,bbcode 不起作用
【发布时间】:2015-12-15 16:38:55
【问题描述】:

第一次使用stackoverflow..很抱歉在这里混淆了。

我刚刚在我的引导网页上实现了 bbcode。 这一切都按我的意愿工作,但是当它工作时,我的导航不起作用。

当我添加这个时:

<script src="//code.jquery.com/jquery-1.11.3.min.js"></script>

到我的页脚,我的导航工作正常,但是我的 bbcode 不能正常工作。

如果我把它注释掉,脚本标签。 bb 代码完美运行,但我的导航无法正常工作...

这是我使用的 BBcode:

<div class="addChatMessage">

<form action="../code/crud.php?action=addToChat" method="POST" class="form-inline">

<div class="form-group">
   <textarea id="test" name="message" class="form-control"></textarea>                                      
</div>
<button type="submit" class="btn btn-success">Send</button>
</form>

<!-- preview bbcode-->

<br><H5 class="white">Preview</H5>

<div id="preview" class="previewbox col-12"></div>



<!-- load ajax library-->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script>

<!-- load custom js -->

<script src='bbedit/jquery.bbcode.js' type='text/javascript'></script>


<script type="text/javascript">

$(document).ready(function(){
                  $("#test").bbcode({tag_bold:true,tag_italic:true,tag_underline:true,tag_link:true,tag_image:true,button_image:true});
                  process();
            });

            var bbcode="";
            function process()
            {
                if (bbcode != $("#test").val())
                {
                        bbcode = $("#test").val();
                        $.get('bbedit/bbParser.php',
                        {
                                bbcode: bbcode
                        },
                        function(txt){
                                $("#preview").html(txt);
                                })

                }
                setTimeout("process()", 2000);

            }



        </script>

在预览 bbcode 中,它应该反映 textarea 中的内容,但根据 bbcode 格式化。

当我激活 jquery 1.11.3.min.js 的脚本时,它会崩溃或停止工作。

当 jquery 被注释掉时,导航不起作用但 bbcode 工作完美......

关于它为什么这样做的任何想法?

【问题讨论】:

    标签: jquery twitter-bootstrap bbcode


    【解决方案1】:

    这是因为您加载 jquery 两次,一次在页脚 (jquery 1.11) 中,一次在代码中

    <!-- load ajax library-->
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script>
    

    我建议你删除上面的代码,只在你的 bbcode 上面添加适当的 jquery 版本。检查 bbcode 是否适用于 jquery 1.11 或让您的导航适用于 jquery 1.3.2

    【讨论】:

    • 这是两个不同的库。并且删除 ajax 没有用。只是让 bb 停止工作,nav 再次工作。
    【解决方案2】:

    我有问题。 问题是您使用了两个不同的 jQuery 库,所以它得到了 conflict 彼此。要消除此问题,您必须使用 jQuery.noConflict(); 所以你的代码将是这样的。试试这个,让我知道,我也有其他想法。

        <div class="addChatMessage">
    
    <form action="../code/crud.php?action=addToChat" method="POST" class="form-inline">
    
    <div class="form-group">
       <textarea id="test" name="message" class="form-control"></textarea>                                      
    </div>
    <button type="submit" class="btn btn-success">Send</button>
    </form>
    
    <!-- preview bbcode-->
    
    <br><H5 class="white">Preview</H5>
    
    <div id="preview" class="previewbox col-12"></div>
    
    
    
    <!-- load ajax library-->
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script>
    
    <!-- load custom js -->
    <script type="text/javascript">
          var $ = jQuery.noConflict();
    </script>
    <script src='bbedit/jquery.bbcode.js' type='text/javascript'></script>
    
    
    <script type="text/javascript">
    
    $(document).ready(function(){
                      $("#test").bbcode({tag_bold:true,tag_italic:true,tag_underline:true,tag_link:true,tag_image:true,button_image:true});
                      process();
                });
    
                var bbcode="";
                function process()
                {
                    if (bbcode != $("#test").val())
                    {
                            bbcode = $("#test").val();
                            $.get('bbedit/bbParser.php',
                            {
                                    bbcode: bbcode
                            },
                            function(txt){
                                    $("#preview").html(txt);
                                    })
    
                    }
                    setTimeout("process()", 2000);
    
                }
    
    
    
            </script>
    

    【讨论】:

    • 添加 var $ = jQuery.noConflict(); 似乎不起作用
    • 我已经更新了我的答案,它应该可以工作....如果仍然无法工作,那么可以提供您的网站网址,以便我检查它
    • 还是不行。该项目是本地的。但你可以在这里查看文件:drive.google.com/… 代码在页面下,页脚在包含下。并且在索引页面上使用了bbcode。
    猜你喜欢
    • 2018-08-14
    • 2020-11-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多