如何使用MVC3显示加载图像(.gif动画文件)自动完成文本框里面 [英] How to show loading image (animated .gif file) inside autocomplete textbox using MVC3

查看:165
本文介绍了如何使用MVC3显示加载图像(.gif动画文件)自动完成文本框里面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经实现自动完成文本框在我的asp.net MVC3的应用程序,但我无法显示在搜索文本框里面装的形象。
我的code是


  

的JavaScript


 <链接rel =stylesheet属性HREF =HTTP://$c$c.jquery.com/ui/1.9.2/themes/base/jquery-ui。 CSS/>
<脚本SRC =HTTP://$c$c.jquery.com/jquery-1.8.3.js类型=文/ JavaScript的>< / SCRIPT>
<脚本SRC =HTTP://$c$c.jquery.com/ui/1.9.2/jquery-ui.js类型=文/ JavaScript的>< / SCRIPT>
< SCRIPT LANGUAGE =JavaScript的类型=文/ JavaScript的>$(文件)。就绪(函数(){
    $(#txtPONO)。自动完成({
        来源:/横断/ GetPONO
        的minLength:2,
        选择:函数(事件,UI){
            $(#hdnPurContID)VAL(ui.item.id)。
        }
    });
});
< / SCRIPT>


  

查看


 < D​​IV的风格=浮动:左;填充:9px 5像素5像素为5px;宽度:80px;垂直对齐:中间
                                类=Fieldhead酒店>
                                输入@ Html.LabelFor(L => l.PurchaseContract.AOPLPONO)
                            < / DIV>
                            < D​​IV的风格=浮动:左;宽度:200像素;填充:为5px 0像素为5px 0像素;>
                                @ Html.TextBoxFor(M = GT; m.PurchaseContract.AOPLPONO,新{@id =txtPONO,@class =文本框,@style =宽度:100%})
                            < / DIV>
                            < D​​IV的风格=浮动:左;宽度:50像素;填充:4PX 0像素0像素为5px;>
                                < IMG ALT =搜索SRC =../../内容/图片/ Search.png/>
                                @ Html.HiddenFor(型号=> model.PurchaseContract.PurContID,新{@id =hdnPurContID})
                            < / DIV>

我要显示文本框里面的小装载图像右侧


解决方案

添加CSS类是这样的。

  .loading
{
    背景:网址(路径图像)不重复的权利中心;
}

现在触发为自动完成搜索选项,打开选项

  $(#txtPONO)。自动完成({
        来源:/横断/ GetPONO
        的minLength:2,
        选择:函数(事件,UI){
            $(#hdnPurContID)VAL(ui.item.id)。
        },
        搜索:函数(){$(本).addClass('装');},
        打开:函数(){$(本).removeClass('装');}    });

甚至更好的解决办法只是用CSS类为

 的.ui-自动完成加载{背景:网址('IMG / loading.gif')不重复右心}

jQuery的 UI的自动完成加载自动运行加载期间加载图片

希望它能帮助

I have implemented Autocomplete textbox in my asp.net MVC3 application, but I am unable to show loading image inside textbox during search. My code is

Javascript

<link rel="stylesheet" href="http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.8.3.js" type="text/javascript"></script>
<script src="http://code.jquery.com/ui/1.9.2/jquery-ui.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript">

$(document).ready(function () {
    $("#txtPONO").autocomplete({
        source: "/Transection/GetPONO",
        minLength: 2,
        select: function (event, ui) {
            $("#hdnPurContID").val(ui.item.id);
        }
    });
});


</script>

View

<div style="float: left; padding: 9px 5px 5px 5px; width: 80px; vertical-align: middle"
                                class="fieldHead">
                                Enter @Html.LabelFor(l => l.PurchaseContract.AOPLPONO)
                            </div>
                            <div style="float: left; width: 200px; padding: 5px 0px 5px 0px;">
                                @Html.TextBoxFor(m => m.PurchaseContract.AOPLPONO, new { @id = "txtPONO", @class = "textbox", @style = "width:100%" })
                            </div>
                            <div style="float: left; width: 50px; padding: 4px 0px 0px 5px;">
                                <img alt="search" src="../../Content/images/Search.png" />
                                @Html.HiddenFor(model => model.PurchaseContract.PurContID, new { @id = "hdnPurContID" })
                            </div>

I want to show a small loading image inside textbox on right side

解决方案

Add a css class like this.

.loading
{
    background:url('path to your image') no-repeat right center;
}

Now trigger to the search option and open options for autocomplete

$("#txtPONO").autocomplete({
        source: "/Transection/GetPONO",
        minLength: 2,
        select: function (event, ui) {
            $("#hdnPurContID").val(ui.item.id);
        },
        search: function(){$(this).addClass('loading');},
        open: function(){$(this).removeClass('loading');}

    });

OR

Even better solution would be just using the css class

.ui-autocomplete-loading { background:url('img/loading.gif') no-repeat right center }

jQuery ui-autocomplete-loading automatically runs the loading image for the duration of loading

Hope it helps

这篇关于如何使用MVC3显示加载图像(.gif动画文件)自动完成文本框里面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆