2015-05-27 71 views
0

我這是怎麼打開的對話框中我發現了一個教程很久以前,我忘了鏈接到該教程對話框獲取HTML跨度值

$("#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得到的跨度值,這樣我可以把它作爲parameter for ajax request

增加一個功能

回答

2

你可以簡單地在「添加」功能執行功能:

... 
"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 
} 
+0

我只是想知道如何得到的跨度值將直接調用跨度ID獲得跨度文本? –

+1

就像我寫的,使用$(「#id或[name =」your_name「]或.class」).text()來獲取所選容器的文本。 – Sojtin