在处理后台任务或提交表单时显示进度图像
我有一个 asp.net 表单。我想在提交表单并且后端发生一些事情时显示 jquery 进度图像。
这是我的 JavaScript:
<script language="javascript">
$(document).ready(function () {
$('#progress').hide();
$("#ProjectNavigation input.bgdiv").click(function () {
$("#progress").show();
$("body").load($(this).attr('href'));
return false;
});
});
单击类设置为“bgdiv”的任一图像将显示动画 gif(如预期),但我想在后端处理完成后隐藏 gif(或它所包裹的 div)。不知道如何实现这一点。我不确定我的 javacsript 中的这一行是否正确,因为我的 html 中没有 href 标记: $("body").load($(this).attr('href'));
非常感谢任何提示。
这是我的标记:
<table id="ProjectNavigation" class="ProjectNavigation" width="100%">
<tr>
<td>Title 1</td><td>Title 2</td><td>Title 3</td><td>Title 4</td>
</tr>
<tr>
<td class="HelpGuidanceLink">Comments
<div id="progress" style="padding:20px 0 0 35px;">
<img src="/_layouts/images/progress-image.gif">
</div>
</td>
<td colspan="3">
<textarea name="CommentsTextBox" rows="3" cols="20" id="CommentsTextBox" class="ProjectGuideTextBox">
other comments testing...
</textarea>
</td>
</tr>
<tr>
<td colspan="4">
<input type="image" name="PreviousPhaseImageButton" id="PreviousPhaseImageButton" class="bgdiv" src="/images/previous-phase-arrow.png" />
<input type="image" name="NextPhaseImageButton" id="NextPhaseImageButton" class="bgdiv" src="/images/next-phase-arrow.png" />
</td>
</tr>
谢谢 -
I have an asp.net form. I want to show a jquery progress image while a form is submitted and there is some stuff happening in the backend.
This is my javascript:
<script language="javascript">
$(document).ready(function () {
$('#progress').hide();
$("#ProjectNavigation input.bgdiv").click(function () {
$("#progress").show();
$("body").load($(this).attr('href'));
return false;
});
});
Clicking on the either images with class set to "bgdiv" is showing the animated gif (as expected), but I want to hide the gif (or div it is wrapped around with) after backend stuff has completed processing. Not sure how to accomplish that. I am not sure if this line is correct in my javacsript since I dont have an href tag in my html: $("body").load($(this).attr('href'));
Any tips are very much appreciated.
Here is my markup:
<table id="ProjectNavigation" class="ProjectNavigation" width="100%">
<tr>
<td>Title 1</td><td>Title 2</td><td>Title 3</td><td>Title 4</td>
</tr>
<tr>
<td class="HelpGuidanceLink">Comments
<div id="progress" style="padding:20px 0 0 35px;">
<img src="/_layouts/images/progress-image.gif">
</div>
</td>
<td colspan="3">
<textarea name="CommentsTextBox" rows="3" cols="20" id="CommentsTextBox" class="ProjectGuideTextBox">
other comments testing...
</textarea>
</td>
</tr>
<tr>
<td colspan="4">
<input type="image" name="PreviousPhaseImageButton" id="PreviousPhaseImageButton" class="bgdiv" src="/images/previous-phase-arrow.png" />
<input type="image" name="NextPhaseImageButton" id="NextPhaseImageButton" class="bgdiv" src="/images/next-phase-arrow.png" />
</td>
</tr>
Thanks -
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
.load()
接受回调函数作为参数。在加载调用中添加一个函数作为第二个参数,以隐藏进度条。关于 href,看起来你是对的 - 它不会按原样工作。您需要告诉 jQuery 要加载的 URL。对我来说,在输入的 value 属性中指定并使用
.val()
检索它似乎是最自然的。这是jsfiddle 的工作演示。
.load()
accepts a callback function as a parameter. Add a function as your second parameter in your call to load that hides the progress bar.Regarding the href, it looks like you're right - it won't work as is. You need to tell jQuery the URL to load. It seems most natural to me to specify that in the input's value attribute and retrieve it using
.val()
.Here's a working demo at jsfiddle.