JQuery:对话框标题未更新

JQuery:对话框标题未更新,jquery,dialog,title,Jquery,Dialog,Title,我需要在选择图像时更新对话框的标题。我在chrome的Inspect元素中进行调试,我对该值的观察见下面的注释: function setDialogTitle(item){ // item is input#searchclassimg.imagewrapper var id = item.id; // gives id of selected element switch(id){ // dialog is a div, whose default title is

我需要在选择图像时更新对话框的标题。我在chrome的
Inspect元素中进行调试,我对该值的观察见下面的注释:

function setDialogTitle(item){ // item is input#searchclassimg.imagewrapper
    var id = item.id;  // gives id of selected element
    switch(id){
    // dialog is a div, whose default title is "Some picker"

    case "searchclassimg":
        $('#dialog').attr('title', 'Class Picker'); //after this i expect dialog's title to be updated as "Class Picker"
        break;
    case "searchsectionimg":
        $('#dialog').attr('title', 'Section Picker');
        break;
    case "searchrollnoimg":
        $('#dialog').attr('title', 'Roll No Picker');
        break;
    case "searchnameimg":
        $('#dialog').attr('title', 'Name Picker');
        break;
    }
}
$(document).ready( function() {
                    if (!window.jQuery) {
                        document
                                .write('<link rel="stylesheet" href="/WEB-INF/lib/jquery-ui-themes-1.10.3/themes/smoothness/jquery-ui.css"><\/link>');
                        document
                                .write('<script src="/WEB-INF/lib/jquery-1.10.1.js"><\/script>');
                        document
                                .write('<script src="/WEB-INF/lib/jquery-ui.js"> <\/script>');

                    }
                    var counter = 0;
                    $(".imagewrapper").click(function() {
                                        $("#dialog").dialog();
                                        setDialogTitle(this);
                                        if (counter < 1) {
                                            $("#searchboxdiv").after('<hr id="separator1">');
                                            $("#separator1").after('<div id="contents" class="container"> </div>');
                                            setDialogItems();
                                            counter++;
                                        }
                                    });
                    $(document).on('click', "#searchbutton", function() {
                        var data1 = $("#searchbox").val();
                        $.ajax({
                            url : "FormHandler",
                            data : {
                                data1 : data1
                            },
                            success : function(result) {
                                var result = null;
                            }
                        });
                    });
函数setDialogTitle(item){//item为输入#searchclassimg.imagewrapper
var id=item.id;//给出所选元素的id
开关(id){
//对话框是一个div,默认标题为“somepicker”
案例“MG”:
$('#dialog').attr('title','Class Picker');//在此之后,我希望对话框的标题更新为“Class Picker”
打破
案例“searchsectionimg”:
$('#dialog').attr('title','Section Picker');
打破
案例“searchrollnoimg”:
$('#dialog').attr('title','Roll No Picker');
打破
案例“searchnameimg”:
$('#dialog').attr('title','Name Picker');
打破
}
}
$(文档).ready(函数(){
如果(!window.jQuery){
文件
.写(“”);
文件
.写(“”);
文件
.写(“”);
}
var计数器=0;
$(“.imagewrapper”)。单击(函数(){
$(“#dialog”).dialog();
setDialogTitle(本);
如果(计数器<1){
$(“#searchboxdiv”)。之后(“
”); 美元(“#分隔符1”)。在(“”)之后; setDialogItems(); 计数器++; } }); $(文档)。在('单击',“#搜索按钮”,函数()上{ var data1=$(“#搜索框”).val(); $.ajax({ url:“FormHandler”, 数据:{ data1:data1 }, 成功:功能(结果){ var结果=null; } }); });
ImageWrapper是定义多个元素的
。 我被处决后得到的只是“一些拾荒者”。
我犯错误的地方请指出。

我假设,由于您标记了此jQuery和对话框,您正在使用jQuery UI对话框小部件。如果是这样,您可以使用对话框上的
选项
功能设置新标题:

$('#dialog').dialog('option', 'title', 'New Title');
因此,您的代码将变成:

function setDialogTitle(item){ // item is input#searchclassimg.imagewrapper
    var id = item.id;  // gives id of selected element
    switch(id){
    // dialog is a div, whose default title is "Some picker"

    case "searchclassimg":
        $('#dialog').dialog('option', 'title', 'Class Picker'); //after this i expect dialog's title to be updated as "Class Picker"
        break;
    case "searchsectionimg":
        $('#dialog').dialog('option', 'title', 'Section Picker');
        break;
    case "searchrollnoimg":
        $('#dialog').dialog('option', 'title', 'Roll No Picker');
        break;
    case "searchnameimg":
        $('#dialog').dialog('option', 'title', 'Name Picker');
        break;
    }
}   


请提供更多代码错误在于无法通过设置对话框小部件容器元素的title属性来更新对话框小部件的标题。只能使用jQuery UI API设置标题。