AJAX AutoComplete的用法

调用页:
//在页面顶部注册控件
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
//TextBox控件
<asp:TextBox ID="txtTo" runat="server" Width="500px" AutoPostBack="True"></asp:TextBox>
<cc1:AutoCompleteExtender ID="AutoCompleteExtenderSearch" 
	MinimumPrefixLength="1"//这是设置输入几个字符才开始调用搜索
	CompletionInterval="10" 
	runat="server"
	EnableCaching="true"
	ServicePath="AutoCompleteSend.asmx"//这是Web Services的路径
	ServiceMethod="GetToAddress"//这是处理搜索的Web Services下的一个方法
	TargetControlID="txtTo">//这是对应的TextBox
</cc1:AutoCompleteExtender>
被调用的Web Services:
using System;

using System.Collections;

using System.ComponentModel;

using System.Data;

using System.Linq;

using System.Web;

using System.Web.Services;

using System.Web.Script.Services;

using System.Web.Services.Protocols;

using System.Xml.Linq;



namespace MySystem.Email

{

    /// <summary>

    /// AutoCompleteSend 的摘要说明

    /// </summary>

    [WebService(Namespace = "http://tempuri.org/")]

    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]

    [ToolboxItem(false)]

    // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。

    [System.Web.Script.Services.ScriptService]//这个很重要,一定要有

    public class AutoCompleteSend : System.Web.Services.WebService

    {



        [WebMethod(EnableSession=true)]//这是打开支持Session的

        [ScriptMethod]//这个很重要,一定要有

        public string[] GetToAddress(string prefixText, int count)

        {

            //这里我就不详细写了,只要返回一个string[]就可以了

            return new string[]{"第一行","第二行"};

        }

    }

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
el-select 是 Element UI 中的一个下拉选择组件,而 autocomplete 是 el-select 组件的一个属性,用于实现自动完成的功能。 当 autocomplete 属性设置为 'true' 时,el-select 组件会根据用户输入的内容自动匹配选项,并展示匹配的结果。用户可以选择匹配的选项,也可以继续输入以进一步过滤选项。 使用 autocomplete 属性需要配合 el-autocomplete 组件一起使用。el-autocomplete 是一个输入框组件,用于接收用户的输入并进行自动完成匹配。 以下是一个示例代码: ```html <template> <div> <el-select v-model="selectedValue" :filterable="true" :remote="true" :remote-method="remoteMethod"> <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value"></el-option> </el-select> </div> </template> <script> export default { data() { return { selectedValue: '', // 当前选中的值 options: [], // 下拉选项 }; }, methods: { remoteMethod(query) { // 远程请求获取匹配的选项 // 这里可以使用异步请求,比如发送 AJAX 请求获取数据 // 然后根据 query 进行过滤 // 最后将过滤后的结果赋值给 options }, }, }; </script> ``` 在上面的代码中,el-select 组件的 autocomplete 属性被设置为 'true',表示启用自动完成功能。通过设置 :filterable="true",可以在输入框中输入内容进行过滤匹配。通过设置 :remote="true" 和 :remote-method="remoteMethod",可以实现远程请求获取匹配的选项,remoteMethod 方法用于处理远程请求的逻辑。 这样,当用户输入内容时,el-select 组件会根据输入内容触发 remoteMethod 方法进行匹配,并将匹配的选项展示出来供用户选择。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值