Javascript 对话框,数据选择器获取id
我对javascript有些陌生,需要为一个项目集成几个插件。是否有方法将Javascript 对话框,数据选择器获取id,javascript,jquery,autocomplete,dialog,Javascript,Jquery,Autocomplete,Dialog,我对javascript有些陌生,需要为一个项目集成几个插件。是否有方法将客户id(在打开对话框窗口时获得,并由autocomplete建议)输入“创建新工单”按钮位置 我想在用户单击“创建新作业”后关闭第一个对话框,然后打开新对话框窗口,但我想将customer\u id从第一个对话框窗口传递到第二个对话框窗口。在调用new\u job()函数之前,可能有一些对话框和自动完成交互我可能不理解,我就是无法获取customer\u id $(function() { $( "#dialog-na
客户id
(在打开对话框窗口时获得,并由autocomplete建议)输入“创建新工单”按钮位置
我想在用户单击“创建新作业”后关闭第一个对话框,然后打开新对话框窗口,但我想将customer\u id
从第一个对话框窗口传递到第二个对话框窗口。在调用new\u job()
函数之前,可能有一些对话框和自动完成交互我可能不理解,我就是无法获取customer\u id
$(function() {
$( "#dialog-name" ).dialog({
autoOpen: false,
})});
function customer_funct(){
$( "#dialog-name" ).dialog( "open" )
$(function() {
var name = $( "#name" );
$( "#name" ).autocomplete({
source: "suggest_name.php",
minLength: 2,
select: function( event, ui ) {
var customer_id = ui.item.customer_id;
// I am able to get customer_id here,
//now I need to pass it to the function below.
}
});
$( "#dialog-name" ).dialog({
autoOpen: false,
height: 300,
width: 500,
modal: true,
buttons: {
"Create new job": function() {
$( this ).dialog( "close" );
cust_name = (name.val());
// is there any way to get "customer_id" at this location
// before I call new_job() function after the user selects customer
// from the database and clicks "Create new job"?
new_job(customer_id, cust_name);
},
Cancel: function() {
$( this ).dialog( "close" );
}
}
});
});
默认情况下,选择事件ui参数仅包含“标签”和“值”属性
为了访问自定义属性,您需要在通过ajax调用检索数据后显式添加它。与此类似 我想我自己想了想才回答了这个问题。如果其他人正在处理jQuery自动完成和对话框交互,并且如果您需要使用上一个对话框窗口中的id值打开新的对话框窗口(在new_job(customer_id))并在成功时关闭上一个对话框窗口:
$(function() {
$( "#dialog-name" ).dialog({
autoOpen: false,
})});
function customer_funct(){
$( "#dialog-name" ).dialog( "open" )
$(function() {
var name = $( "#name" );
$( "#name" ).autocomplete({
source: "suggest_name.php",
minLength: 2,
select: function( event, ui ) {
var customer_id = ui.item.customer_id;
new_job(customer_id);
$(this).val(''); return false;
}
});
$( "#dialog-name" ).dialog({
autoOpen: false,
height: 300,
width: 500,
modal: true,
buttons: {
"Create new job": function() {
alert('Please select customer or click "Add New" customer');
},
Cancel: function() {
$( this ).dialog( "close" );
}
}
});
});
}
请更好地修改您的代码片段。在发布之前,在复制粘贴后检查预览中的外观是否正确。还要创建一个JSFIDLE.net FIDLE,这样我们可以更容易地查看html和调试。抱歉,现在在stackoverflow.com上编辑了它的显示方式,看起来更好。您也可以发布html代码。如果可能,在[link](jsfiddle.net)创建一个提琴