2014-09-26 60 views
0

我得到所有聯繫人從Mysql數據庫,然後顯示它在html行。每行有onClick()方法點擊後各行它會顯示聯繫人的詳細信息的右側所有聯繫人如何檢查其他頁面字段值是否使用jquery

顯示所有聯繫人:

echo "<tr onclick='getDetails($cdid), showthirdbox($cdid), visited(this);'>";        
echo "<td class='' valign='top' align='left' width='20'>$companyName</td>"; 
echo "<td class='' valign='top'>$family_name</td>"; 
echo "<td class='' valign='top'>$given_name</td>"; 
echo "<td class='' valign='top'>$department</td>"; 
echo "<td class='' valign='top'>$title</td>";  
echo "</tr>"; 

getDetails()呼叫getContactDetails.php(聯繫方式)頁面。在這個頁面中,我有一個名爲Note的字段,用戶可以在其中輸入筆記。

所以現在我想顯示確認消息用戶只有當用戶寫東西就Enter Note框,但點擊其他(所有聯繫人)沒有保存該Enter Notes

確認mesaage將是:做你想在保存這個Notes框之前,你去其他聯繫人?是或否如果是,則saveNote()將被呼叫,否則它將加載新的聯繫人行。

我不知道如何使用jquery或Javascript來做到這一點?你有什麼想法或解決方案嗎?謝謝。

getDetails()函數:

function getDetails(id) { 
      id = id; 
      $.ajax({ 
      type:"post", 
      url:"getContactDetails.php", 
      data:"id="+id, 
      success:function(res){ 
       $('#visiable').show(); 
       $('#notebox_visiable').show(); 
       $('#thirdBox').show(); 

       $('#all_contact_details').html(res); 
       showthirdbox(id); 
       //showNotexBox(id); 
       //showAllNotesBox(id); 
       } 
      }); 
} 

getContactDetails.php頁有Note場:點擊後一排

<tr> 
    <td colspan="2">Enter Note<p id="demo"></p></td> 
</tr> 
<tr> 
    <td colspan="2">   
    <center><img id="loading-image" src="images/loading-image.gif" style="display:none; margin-bottom:10px !important;"/></center> 
    <div id="Notesboxsuccess"></div> 
    <form action="" method="post" id="showNotesBox" name="notebox">  
    <input type="hidden" value="<?php echo $id; ?>" name="cdid" id="cdid"/> 
<tr> 
    <td colspan="2"><textarea name="contentText" id="contentText" cols="35" rows="4" placeholder="enter note"></textarea></td> 
</tr> 
<tr> 
    <td colspan="2">&nbsp;</td> 
</tr> 
<tr> 
    <td colspan="2"><input type="submit" value="Save" name="submit" class="submit" id="addNewNotes"/></td> 
</tr> 
    </form> 

主頁視圖(所有聯繫人):

enter image description here

+0

你可以這樣做:添加一個'onchange'處理程序的說明框。在該處理程序中,爲文本字段設置一個自定義屬性,如$(notebox).attr('change','yes')'。然後在你的聯繫人列表的「onclick」中,在你改變任何東西之前,檢查一下notebox是否有一個屬性「change = yes」並顯示你的問題。 – Michel 2014-09-26 04:59:14

+0

@Michel感謝您的回覆。你能告訴我如何做到這一點嗎? – Shibbir 2014-09-26 05:06:28

回答

0

change只觸發模糊,所以只要用戶停留在文本框中,就沒有任何事情要做。

jQuery change()

連接change事件處理函數:

$("#contentText").change(function() { 
    $("#contentText").attr("ididwritesomething","yep"); 
    } 

在保存按鈕刪除屬性jQuery removeAttr()

$("#contentText").removeAttr("ididwritesomething"); 

在您的聯繫人列表中單擊處理程序,檢查屬性設置爲(from this question)

var attr = $("#contentText").attr("ididwritesomething"); 
if (typeof attr !== typeof undefined && attr !== false && attr=="yep"){ 
     //do you want to save? 
} 
0

在這裏你可以使用jQuery Change函數來做到這一點。 例如,

<input id="field" type="text" value="abcd"> 
<a id="pid" href="#">Link</a> 

對於上面的html代碼jQuery代碼是繼

$(document).ready(function(){ 
$("#pid").click(function(){ 
    $("#field").change(function(){ 
    alert("The text has been changed."); 
    });// end of change 
});// end of click function 
});//end of document 
相關問題