如何使用jquery live函數時只提交點擊事件(div)?如何使用jquery live函數時只提交點擊事件(div)?
我在做什麼。
點擊輸入並在mysql中搜索聯繫人。 點擊聯繫人並將聯繫信息插入數據庫。 這項工作 我遇到的問題是,它將頁面上的所有while循環插入到msql數據庫,我需要一些幫助解決這個問題。
PHP代碼時搜索激活負載:
這是一個while循環:
<?php
echo '
<div id="'.$get_memID.'" class="box_content">
<table width="100%">
<tr>
<td width="50%" align="left"> '.$profile_pic_lil.' <span style="font-size: 14px; font-weight: bold; color: #060; ">'.$get_memfirstName.' '.$get_memlastName.'</span></td>
<td width="40%"align="right" valign="top">
<span style="font-size: 12px; color: #999999;">'.$linkUP_As.'</span>
<input name="to_mem" type="hidden" id="to_mem" value="'.$get_mem.'" />
<input name="to_memID" id="to_memID" type="hidden" value="'.$get_memID.'" />
<input name="to_memfirstName" id="to_memfirstName" type="hidden" value="'.$get_memfirstName.'" />
<input name="to_memlastName" type="hidden" value="'.$get_memlastName.'" />
</td>
</tr>
</table>
</div>
';
?>
jQuery腳本加載搜索:
$(document).ready(function(){
var timer;
$(".search").live('keyup',function(e){
clearTimeout(timer);
var ms = 200; // milliseconds
var val = this.value;
timer = setTimeout(function() {
lookup(val);
}, ms);
var dataString = 'mysearchString='+ val;
if(val==''){
} else {
$.ajax({
type: "POST",
url: "/happening_searchlinkUP.php",
data: dataString,
cache: false,
success: function(html){
$("#display<?php echo $id; ?>").html(html).show();
}
});
}
return false;
});
});
jQuery腳本到PHP文件發送到MySQL的:
$(document).ready(function(){
$(".box_content").live('click',function(e){
var element = $(this);
var id = element.attr("id");
var mem_email = $("#to_mem").val();
var mem_firstName = $("#to_memfirstName").val();
var happening_id = $("#happening_id<?php echo $id; ?>").val();
var info = "id=" + id + '&mem_email=' + mem_email + '&mem_firstName=' + mem_firstName + '&happening_id=' + happening_id;
$.ajax({
type: "POST",
url: "/happening_getMem_linkUP.php",
data: info,
cache: false,
success: function(html){
$("#now_from_linkup<?php echo $id; ?>").html(mem_firstName);
}
});
return false;
});
});
任何幫助欣然接受,並在此先感謝
你的問題不清楚,你能澄清一下嗎?另外,一些代碼格式很糟糕,您能否讓您的代碼更易於閱讀? – Jasper 2012-02-28 18:54:01
真的不清楚你的問題是什麼 – charlietfl 2012-02-28 18:54:02
當提交表單數據庫它插入不止一次 – Kasagi 2012-02-28 18:58:31