[問題]用jquery ajax帶出來的元素用jquery給事件無效
我有一個頁面一刷新會用jquery ajax帶一些html元素放到網頁中
這些帶出來的元素有辦法再給他按鈕事件嗎?
試試好像沒效
該如何改進
<script type="text/javascript">
$(function(){
$.MyExtend.showOnline();
$("input[name='hh']").click(function(){alert("dd");});
});
$.MyExtend={
showOnline:function(){
alert("enter!!");
$.ajax({
type:"GET",
url:"online.jsp",
//dataType:text,
success:function(msg){
//alert("suucess");
$("#online").html(msg);
},
error:function(){
alert("error!!");
}
});
},
showContent:function(){
$.ajax({
type:"GET",
url:"online.jsp",
success:function(msg){
//alert("suucess");
$("#online").html(msg);
},
error:function(){
alert("error!!");
}
});
},
sendMessage:function(){
if($("input[name='name']").val()==''){
alert("請輸入對象!!");
return false;
}
if($("input[name='talk_content']").val()==''){
alert("發送訊息不能為空!!");
return false;
}
var from=$("input[name='name']").val();
var to=$("input[name='to']").val();
var content=$("input[name='talk_content']").val();
//var from=$("input[name='name']").val();
$.ajax({
type:"POST",
dataType:"jSon",
url:"MessageServlet?action=sendMessage",
success:function(msg){
//alert("suucess");
$("#online").html(msg);
},
error:function(){
alert("error!!");
}
});
},
selectOne:function(){
//var username=$("#selectone").val();
//$("input[name='to']").val(username);
//alert("hello");
$(this).click(function(){
alert("hello");
});
}
}
</script>
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.113.200.225
※ 文章網址: http://www.ptt.cc/bbs/Web_Design/M.1414981933.A.C75.html
推
11/03 11:14, , 1F
11/03 11:14, 1F
推
11/03 12:19, , 2F
11/03 12:19, 2F
→
11/03 12:20, , 3F
11/03 12:20, 3F
推
11/03 20:23, , 4F
11/03 20:23, 4F
推
11/24 12:55, , 5F
11/24 12:55, 5F