将jQuery选择的项目绑定到div [英] binding jquery selectd item into div

查看:104
本文介绍了将jQuery选择的项目绑定到div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自动完成的文本框,该文本框中正在获取员工姓名.如果我单击该特定员工的姓名,则该特定员工的详细信息(例如照片,姓名,身份证号,联系人)不应将这些详细信息添加为框式容器(与大多数站点中的标签框相同,我应该能够通过单击其角落的十字标记来删除特定记录),例如单击多少名员工姓名,应在该文本框下方添加很多记录,我该怎么做以及我拥有哪种工具用这个,谁能帮我

函数searchEmployees(){

$(#txtEmployee").autocomplete({

来源:功能(请求,响应){
$ .ajax({
类型:"POST",
网址:"/DataService.asmx/SearchEmployees",
contentType:"application/json; charset = utf-8",
数据:"{" searchTerm:""+ $("#txtEmployee).val()+"''},
dataType:"json",
成功:函数(数据){
var s = jQuery.parseJSON(data.d);
var i = 0;
var css =";

if(s!= null){

response($.map(s,function(item){{br/> i ++;
if(i == s.length){
css ="autocompletetablenoborder";
}
其他{
css ="autocompletetable";
}
返回{

标签:"

" + item.Name +(" + item.USN +)
"+项目.电子邮件+"   |  "+ item.Mobile +"
",
名称:item.Name

}
}));
}
其他{
返回null;
}

},
错误:功能(要求,状态,错误){
alert("ERROR:" + error.toString()+" + status +" + req);

}
});
},
minLength:1,

选择:函数(事件,用户界面){
$(#Employee").val(ui.item.name);
返回false;
}
});

}
在这里,您可以看到我们在从中选择特定员工后,尝试在div中添加员工姓名(实际上我需要显示员工图像,联系电话,身份证...但仅是为了尝试仅尝试绑定姓名).自动完成列表,但无法正常工作,任何人都可以找出问题吗

I have a autocomplete textbox, in that textbox am getting employee names. If I click that particular employee name, that particular employee''s details like photo,name,id,contact no these kind of details should be added as a box container(just same as the tags box in most of the sites, I should able to delete particular record by clickin the cross mark in its corner), like this how many employee''s name em clicking on, that much of records should be added below that textbox, how can I do this, and which tool I have to use for this, can anyone help me

function searchEmployees() {

$("#txtEmployee").autocomplete({

source: function (request, response) {
$.ajax({
type: "POST",
url: "/DataService.asmx/SearchEmployees",
contentType: "application/json; charset=utf-8",
data: "{''searchTerm'' : ''" + $("#txtEmployee").val() + "''}",
dataType: "json",
success: function (data) {
var s = jQuery.parseJSON(data.d);
var i = 0;
var css = "";

if (s != null) {

response($.map(s, function (item) {
i++;
if (i == s.length) {
css = "autocompletetablenoborder";
}
else {
css = "autocompletetable";
}
return {

label: "

<img src=''" + item.Photo + "'' Width=''48'' Height=''48'' />" + item.Name + " ( " + item.USN + " )
" + item.Email + " | " + item.Mobile + "
",
name: item.Name

}
}));
}
else {
return null;
}

},
error: function (req, status, error) {
alert("ERROR:" + error.toString() + " " + status + " " + req);

}
});
},
minLength: 1,

select: function (event, ui) {
$("#Employee").val(ui.item.name);
return false;
}
});

}
here as you can see am trying to add the employee name(actually I need to display employee image,contact no, id...but just for trial am trying to bind name only) in the div, after we select a particular employee from the autocomplete list, but its not working, can anyone find out the issue

推荐答案

(#txtEmployee").autocomplete({

来源:函数(请求,响应){
("#txtEmployee").autocomplete({

source: function (request, response) {


.ajax({
类型:"POST",
网址:"/DataService.asmx/SearchEmployees",
contentType:"application/json; charset = utf-8",
数据:"{" searchTerm:""+
.ajax({
type: "POST",
url: "/DataService.asmx/SearchEmployees",
contentType: "application/json; charset=utf-8",
data: "{''searchTerm'' : ''" +


("#txtEmployee).val()+"''},
dataType:"json",
成功:函数(数据){
var s = jQuery.parseJSON(data.d);
var i = 0;
var css =";

if(s!= null){

响应(
("#txtEmployee").val() + "''}",
dataType: "json",
success: function (data) {
var s = jQuery.parseJSON(data.d);
var i = 0;
var css = "";

if (s != null) {

response(


这篇关于将jQuery选择的项目绑定到div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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