0

我需要在选择图像时更新对话框的标题。我在 chrome 中调试,Inspect Element我对这个值的观察在下面的评论中给出:

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;
                            }
                        });
                    });

ImageWrapper<div>在其下定义了多个元素。执行后我得到的只是“一些选择器”。我在哪里犯错请指出。

4

1 回答 1

1

我假设既然您标记了这个 jQuery 和 Dialog,那么您正在使用 jQuery UI Dialog 小部件。如果是这样,您可以使用option对话框上的功能来设置新标题:

$('#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;
    }
}   

http://api.jqueryui.com/dialog/#method-option

http://api.jqueryui.com/dialog/#option-title

于 2013-06-19T14:01:57.650 回答