我正在尝试在我的网站上运行多个valum文件上传器实例。它适用于一个实例,但任何时候我循环初始化代码,想要多个按钮我看不到任何按钮。这是代码:
<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>
知道如何获取多个实例吗?提前谢谢!
答案 0 :(得分: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
,所以我在它们前面添加了查询名称,以便对它们进行正确的范围。这通常不是必需的,但出于性能原因(除其他事项外)这是很好的做法。