在.html函数</script>中插入<script>标记

时间:2013-03-28 15:49:48

标签: javascript jquery jsf

我想在no中声明的.html函数内插入以下代码。 2.但是我遇到了一个错误,我遇到的问题是每当我在.html函数中添加它时,$(document).ready()函数所在的外部脚本标记不起作用,它就是说找不到

的起始标记

1)要插入.html函数的代码。

<script>
    <c:forEach items="#{notificationBean.growlNotificationList}" var="p" varStatus="loop">
                            <script>
                    /*           */
                    $.gritter
                            .add({
                                // (string | mandatory) the heading of the notification
                                title : 'Notification for your #{p.objectType}',
                                // (string | mandatory) the text inside the notification
                                text : '#{notificationBean.notificationSenderName(p.senderEmail)} commented on your #{p.objectType}',
                                // (bool | optional) if you want it to fade out on its own or just sit there
                                sticky : true,
                                // (int | optional) the time you want it to be alive for before fading out (milliseconds)
                                time : 8000,
                                // (string | optional) the class name you want to apply directly to the notification for custom styling
                                class_name : 'gritter-light',
                                // (function | optional) function called before it closes
                                before_close : function(e, manual_close) {
                                    document.getElementById("foo#{loop.count}:bar").click();
                                }
                            });
                    /*     */
                </script>

                <h:form id="foo#{loop.count}" style="display:none">
                    <h:commandLink id="bar"
                        action="#{notificationBean.set0ToGrowlToShow(p.notificationID)}">
                        <f:ajax />
                    </h:commandLink>
                </h:form>
            </c:forEach>
</script>

2)要插入的代码

<script>

    $(document).ready(function(){
          setTimeout( function(){
            $("<div>")
              .html( "" )
              .attr({ id : 'notification', ... })
              .appendTo( "body" /* or any other DOM element */ );
          }, 60*1000);
        })

    </script>

1 个答案:

答案 0 :(得分:1)

您可以使用以下jQuery方法动态加载脚本

<script type="text/javascript">
    jQuery(document).ready(function(){
        var url = "https://raw.github.com/jquery/jquery-color/master/jquery.color.js";
        jQuery.getScript(url);
    }); 

相关问题