0

我有一个文本框,我试图获得这样的价值

$(function(){
    comment = $("#diaMissedPucomments").val();
});

当我为文本框提供一些静态值时,这让我获得了价值,而当我允许用户动态输入值时,这并没有让我获得价值。

这是我拥有的 html 代码:

<div style="display:none;" id="diaMissedPU" title="Missed P/U Comments" >
                       <table>
                            <tr>
                               <td>Enter Comments : </td>
                               <td><input type="text" id="diaMissedPucomments" name="diaMissedPucomments" />
                                <input type="text" id="textid" name="textid" value="antony" /></td>
                           </tr>
                       </table>
                    </div>

<input type="text" id="textid" name="textid" value="antony" />我已经使用这条线进行检查,我能够获得价值textid但不能获得价值diaMissedPucomments

更新 :

 function openMissedPUComments(){
        var selectedValues = "",comment="";
        $('input:checked').each(function() {
              selectedValues =$(this).val()+","+selectedValues ;
            });
        if(selectedValues.length==0 && selectedValues==""){
            alert("To run this agent you must have at least one document selected");
            return false;
        }else{
          $("#diaMissedPU")
            .dialog(
                    {
                        modal: true,
                        draggable: false,
                        closeOnEscape: true,
                        title: "Missed P/U Comments ",
                        resizable: false,
                        width: 380,
                        // open: function() {
                        //            
                        // },
                        buttons: {
                            Ok: function () {
                                 comment = $("input#diaMissedPucomments").val();
                                 alert("comment : "+comment);
                                 viewname="CIMtrek_Compliance_Daily_Shipments_Case_Pack_Update_MissedPUs";
                                //callHome(viewname,comment);
                                global.getElementById("diaMissedPucomments").value="";
                                $(this).dialog('close');
                            }
                        }
                    });
        }
    }

将调用上述函数以将 div 作为对话框打开。

如何完成这项工作。

请帮我得到这个。

最好的祝福

4

2 回答 2

1

我认为您误解了对话框的用法。

设置对话框将自动隐藏它,而不是自动打开它。

只需将此属性设置为不自动打开:

autoOpen: false

例如,查看这些更改:代码中的注释

var comment = ""; //global to hold comment text
$(document).ready(function() {// put in a document ready handler
    $("#diaMissedPU").dialog({
        modal: true,
        autoOpen: false,
        draggable: false,
        closeOnEscape: true,
        title: "Missed P/U Comments ",
        resizable: false,
        width: 380,
        buttons: {
            Ok: function() {
                var mycomments = $("input#diaMissedPucomments");//save to reuse
                comment = mycomments.val();//get value
                alert("comment : " + comment);
                viewname = "CIMtrek_Compliance_Daily_Shipments_Case_Pack_Update_MissedPUs";
                //callHome(viewname,comment);
                mycomments.val("");// clear value
                $(this).dialog('close');
            }
        },
        close: function(event, ui) {// use this or not, just to illustrate
            alert(comment);
        }
    });
    $("#wackme").click(function() {// button to activate your function
        openMissedPUComments();
        alert("commentbefore : " + comment); //NOTE: runs before dialog closes
    });
});

function openMissedPUComments() {
    var selectedValues = "";
    comment = "";//clear value in variable
    $('input:checked').each(function() {
        selectedValues = $(this).val() + "," + selectedValues;
    });
    if (selectedValues.length == 0 && selectedValues == "") {
        alert("To run this agent you must have at least one document selected");
        return false;
    } else {
        $("#diaMissedPU").dialog("open");
    }
}

示例工作:http: //jsfiddle.net/Hw6ZA/

于 2013-01-02T14:25:01.907 回答
0

它来了。只要检查这个..

$("#diaMissedPucomments").blur(function() {
    comment = $("#diaMissedPucomments").val();
    alert(comment);
});

我不知道你为什么给 style="display:none;"

于 2013-01-02T13:03:54.933 回答