2014-09-19 66 views
1

受網頁這個問題直接關係到我這裏問的問題是: stop click() from happening on a ajax created input。員額()返回的ID沒有被jQuery的

我的,如果(e.target =簡單地增加想通了這個問題的答案一個==這個),但是現在當我檢查框時,我的返回響應不會做任何事情。

正由我的。員額返回的新代碼是:

$output .= "<table><tr><td>"; 
$output .= "<input id=\"toedit\" type=\"text\" placeholder=\"$item_to_edit\" size=20>"; 
$output .= "</td><td>"; 
$output .= "<input id=\"test_editing_check\" type=\"checkbox\" name=\"test_editing_check\" value=\"test_editing_check\" \>"; 
$output .= "</td></tr></table>"; 

但我的jQuery的是原來的網頁上:

$("#testing_editing").click(function(e){ 
    if (e.target === this) { 
     var testhtml = $(this).html(); 
     var meatseafood = '<?php echo $meatseafood; ?>'; 
     $.post('edit_order.php', {'itemtoedit':testhtml,'meatseafood':meatseafood}, function(data) { //make ajax call to check_username.php 
     $("#testing_editing").html(data); //dump the data received from PHP page 
     }); 
    } 
    }); 
    $("#test_editing_check").click(function(){ 
     if (this.checked) { 
      var testvalue = "HI"; 
      alert(testvalue); 
     } 
    }); 

似乎並沒有對檢查工作該框由.post()調用返回。

有什麼我需要做的,以使一個.post()返回被主頁的jQuery代碼識別? 我希望它的語法沒有問題,但是我在另一個頁面上使用了這個確切的(非常基本的)代碼(但沒有使用.post()調用)並且它工作正常。

基本上,當您單擊div時我的主頁寫入,它會調用.post()並返回一個可編輯的輸入字段和一個複選框。當我點擊該複選框時,我想讓它再次調用.post(),並用新輸入的數據更新數據庫。

但是,當我檢查複選框沒有任何反應。

這似乎是我的ajax返回的代碼無法從原始/主頁面的jQuery中識別。 與我的測試代碼所有我想要做的是彈出一個警告框,當我點擊複選框,以表明它已經「讀」輸入框,現在可以通過.post()調用發送該數據進行處理。

讓我知道你是否需要任何其他代碼。 它似乎很乾淨,但我不知道爲什麼它不工作,這就是爲什麼我在這裏:)

(我想要做的是,用戶提交的想法是,在下一頁上,顯示一個「確認框」,表示「這是你想要用你的表格提交的內容嗎?如果答案是否定的,他們可以」點擊「數據並改變它,而不必重新加載頁面。咔嗒部分作品,但承認「是的,我想我的數據更改爲這個新輸入的數據」複選框不工作。)

感謝您的幫助。

德里克·康倫

回答

0

嘗試將事件加載複選框這樣分配後:

$("#testing_editing").click(function(e){ 
    if (e.target === this) { 
     var testhtml = $(this).html(); 
     var meatseafood = '<?php echo $meatseafood; ?>'; 
     $.post('edit_order.php', {'itemtoedit':testhtml,'meatseafood':meatseafood}, function(data) { //make ajax call to check_username.php 
      $("#testing_editing").html(data); //dump the data received from PHP page 

      // This is applied after loading the data from the ajax call 
      $("#test_editing_check").click(function(){ 
       if (this.checked) { 
       var testvalue = "HI"; 
       alert(testvalue); 
       } 
      }); 
     }); 
    } 
    }); 
+1

這是一個超快速的響應和你點上。 – DerekConlon 2014-09-19 01:20:30

+0

是的,希望我的回答有效@DerekConlon – CMPS 2014-09-19 01:22:36

+1

它像一個魅力。 – DerekConlon 2014-09-19 01:33:58