[英]How to check the input checkbox field with a value on page load using jquery
[英]How to Check if other page field value is empty using jquery
我从MySQL数据库获取所有联系人 ,然后将其显示在html行上。 每行都有onClick()
方法单击每行后 ,它将在所有联系人的右侧显示联系人的详细信息 。
显示所有联系人:
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
确认消息将是:您要在转到其他联系人之前保存此注释框吗? 是或否。如果是,则将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"> </td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="Save" name="submit" class="submit" id="addNewNotes"/></td>
</tr>
</form>
单击一行后的主页视图(所有联系人):
change
仅在模糊时触发,因此只要用户停留在文本框中,就无需执行任何操作。
附加更改事件处理程序:
$("#contentText").change(function() {
$("#contentText").attr("ididwritesomething","yep");
}
在保存按钮中,删除属性jQuery removeAttr()
$("#contentText").removeAttr("ididwritesomething");
在您的联系人列表的点击处理程序中,检查属性是否已设置(根据此问题) :
var attr = $("#contentText").attr("ididwritesomething");
if (typeof attr !== typeof undefined && attr !== false && attr=="yep"){
//do you want to save?
}
在这里,您可以使用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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.