簡體   English   中英

對話框在單擊jquery上獲取html span值

[英]dialog get html span value on click jquery

這是我打開對話框的方法,很早以前我找到了一個教程,卻忘記了該教程的鏈接

$("#dialog1").html("Mr. " + "<span id='name'>" + data[i].name + "</span>" + "has a building property in <span id='address'>" + data[i].address + "</span>");
$("#dialog1").dialog({title: pml});
$("#dialog1").dialog("open");

這就是我創建對話框的方式

var div = $("<div id='dialog1'>");
    $("body").prepend(div);
    $("#dialog1").dialog({
        autoOpen: false,
        resizable: false,
        modal: true,
        //title: "Modal",
        height: 250,
        width: 400,
        buttons: {
            "Add": function() {
                $(this).dialog('close');
            },
                "No": function () {
                $(this).dialog('close');
            },
        "close": function () {
            $(this).dialog('close');
        }
        }
    });

目前,按鈕add and no具有關閉對話框的功能,但是我想添加一種功能,即add button(which is inside the dialog box) is clicked我會在html of the dialog獲得span的值html of the dialog以便我可以將其用作parameter for ajax request

您只需在“添加”功能中執行功能即可:

...
"Add": function() {
            $(this).dialog('close');
            somefunction($('#span_id').text());  // #span_id = id of span whitch you want to get text from
},
...

function somefunction(text) {
   // ajax call
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM