0

我正在尝试让多个值文件上传器实例在我的网站上运行。它适用于一个实例,但无论何时我循环初始化代码,想要多个按钮,我都看不到任何按钮。这是代码:

<cfoutput query="getTopics">

<script>        
    function createUploader(){            
        var uploader = new qq.FileUploader({
            element: document.getElementById('file-uploader#refTopicID#'),
            action: 'components/ProjectBean.cfc',
            params: {method: 'Upload',
                    topicID: #refTopicID#,
                    count: #Evaluate("session.#refTopicAbv#Count")#,
                    topicName: '#refTopicAbv#'
                    },
            encoding: 'multipart'
        });           
    }

    // in your app create uploader as soon as the DOM is ready
    // don't wait for the window to load  
    window.onload = createUploader;     
</script>

<div class="row" id="file-uploader#refTopicID#">        
</div>

知道如何获得多个实例吗?提前致谢!

4

1 回答 1

1

您正在循环内创建一个 javascript 函数。换句话说,您多次定义它。

相反,您应该将 createUploader 函数移到循环之外。在循环中,只需为每个主题多次调用它。

像这样的东西:

<script>        
    function createUploader(elementID, topicID, topicCount, topicName){            
        var uploader = new qq.FileUploader({
            element: document.getElementById(elementID),
            action: 'components/ProjectBean.cfc',
            params: {method: 'Upload',
                    topicID: topicID,
                    count: topicCount,
                    topicName: topicName
                    },
            encoding: 'multipart'
        });           
    }   
</script>

<cfoutput query="getTopics">
<script>        
    createUploader('file-uploader#getTopics.refTopicID#', #getTopics.refTopicID#, #session[getTopics.refTopicAbv & "Count"]#, '#getTopics.refTopicAbv#');   
</script>

<div class="row" id="file-uploader#getTopics.refTopicID#"> </div>
</cfoutput>

注意:我假设这些值都来自您的查询getTopics,所以我在它们前面加上了查询名称,以便正确地确定它们的范围。这通常不是必需的,但出于性能原因(除其他外),这是一种很好的做法。

于 2013-10-07T12:51:48.660 回答