在 ASP.NET MVC 的部分视图内执行 Javascript
我在 head 标签内使用此 JavaScript 代码,以便使用浏览按钮填充 div,以便用户可以上传图像 (swfupload)。
<head>
...
<script type="text/javascript">
var swfu = function() {
return new SWFUpload({
// Backend Settings
// settings go here...
// Too long to display here
// Debug Settings
debug: false
});
}
window.onload = swfu;
</script>
</head>
....
<div id="swfu_container" style="margin: 0px 10px;">
<div>
<span id="spanButtonPlaceholder"></span>
</div>
<div id="divFileProgressContainer" style="height: 75px;"></div>
<div id="thumbnails"></div>
</div>
这工作得很好,但问题是当我尝试将此代码放入部分视图中时。到目前为止,我还无法让它发挥作用。
有没有更有经验的人来救救?
谢谢
I use this JavaScript code inside the head tag in order to populate the divs with a browse button so that users can upload images (swfupload).
<head>
...
<script type="text/javascript">
var swfu = function() {
return new SWFUpload({
// Backend Settings
// settings go here...
// Too long to display here
// Debug Settings
debug: false
});
}
window.onload = swfu;
</script>
</head>
....
<div id="swfu_container" style="margin: 0px 10px;">
<div>
<span id="spanButtonPlaceholder"></span>
</div>
<div id="divFileProgressContainer" style="height: 75px;"></div>
<div id="thumbnails"></div>
</div>
This works well, but the problem is when I try to put this code inside of a partial view. So far, I haven't be able to get this to work.
Is there anyone more experienced to the rescue?
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你可以这样放置你的函数:
这样如果你的更新成功,你的 swfu 函数将被调用
You can put your function like this:
so your swfu function will be called if your update is successfull
window.onload 的目的是在页面完成加载后执行给定的函数。也就是说,您应该考虑将负载移动到主体的底部。而且我并不热衷于把剧本记在脑子里。 :)
The point of window.onload is to execute the given function once the page has finished... loading. That said, you should consider moving the onload to the bottom of the body. And I'm not the worlds biggest fan of keeping scripts in the head. :)
部分视图使用 Microsoft Ajax 呈现,不会评估 JavaScript 代码。我建议在这种情况下不要使用部分视图,或者看看 Spark 等其他视图引擎......或者将所有必需的 javascript 放在您的父视图中,这会让您的代码有点草率
Partial views are rendered with Microsoft Ajax which does not evaluate JavaScript code. I would suggest looking at not using partial views in this case or look at other view engines like Spark....or put all required javascript in your parent view which kinda makes your code a bit sloppy