我有一個情況我生成使用jQuery動態HTML一樣的onclick jQuery的不工作
var list_of_addressbook_entries = {};
var filter = []
function save(){
var user = $("#addressbook_user").val();
var desg = $("#desg").val();
var ahtml='<div id ="user_'+user+'" class="addr_list" style=" font-size: 30px;display:block; background: none repeat scroll 0% 0% peachpuff;margin:1px 1px 1px 1px ;">'
ahtml = ahtml + '<span style="display: block; float: left; font-size: 30px; margin: 2px 24px 2px 21px;" >'+user+'</span>'
if(desg == 'M'){
ahtml = ahtml + '<span style="display: block; float: left; font-size: 30px; margin: 2px 24px 2px 21px;">Moderator</span>'
}
else{
ahtml = ahtml + '<span style="display: block; float: left; font-size: 30px; margin: 2px 24px 2px 21px;">Attendee</span>'
}
ahtml = ahtml + '<div onclick="remove_video(\''+user+'\')"><span ><img src="/UI/user/img/delet.jpeg" alt="Smiley face" height="42" width="42" /> </span></div></div>'
var ua = "'"+user+"'";
filter.push(ua);
$.ajax({
type: "GET",
url: "<?php echo SITE_URL;?>/UI/user/filterbox.php",
data: "list="+ filter+"&Where=addressbook" ,
success: function(json){
$('#addorguser').html(json);
// if(!json.error) location.reload(true);
},
error: function (xhr, textStatus, errorThrown) {
alert(json);
}
});
$("#organization").append(ahtml);
}
function remove_video(user){
alert(user);
$("#user_"+user).hide();
}
調用保存()本人附加動態HTML生成一個div有我還定義了一個remove_video功能後在動態html中。
但是,當我點擊動態div刪除div remove_video函數沒有被調用。
我也沒有得到任何錯誤。
幫我看看。
* 更新的HTML *
<div id="organization" name="organization">
</div>
<div>Address Book</div><br>
<div id="box1">
<?php
if (isset($_SESSION["user_name"])){
$get_user_name = $_SESSION["user_name"];
?>
<div id="addorguser" style="display: block; float: left;">
<select id ="addressbook_user" name="addressboook_user">
<?php
$asql = "SELECT * from demo_addressbook WHERE user_created_id IN(SELECT id FROM demo_user WHERE user_name = '$get_user_name') AND type = 1 ";
// $result = mysql_query($query);
// mysql_real_escape_string($asql);
$aresult = mysql_query($asql) or die (mysql_error());
while($arow_list=mysql_fetch_assoc($aresult)){
?>
<option value="<?php echo $arow_list['guest_name']; ?>"><?php echo $arow_list['guest_name']; ?></option>
<?php
}
?>
</select>
</div>
<select name="desg" id="desg">
<option value="A">Attendee</option>
<option value="M">Moderator</option>
</select>
<input type="button" id ="aadd" onclick="save()" name="button" value="Add"/>
</div>
<?php
}
?>
PHP的大混亂+ MYSQL + HTML + JS +內嵌CSS :考慮在生氣之前學習關於分離問題。 – moonwave99
建議我一些解決方案或鏈接 – user1667633
從這裏開始:http://stackoverflow.com/questions/639622/separation-of-concerns-mvc-why – moonwave99