/*經過用戶技能標簽增加樣式*/
$(".s-edited").live("hover",function(){
$(this).toggleClass("borderd");
})
===================================
<!DOCTYPE html PUBLIC
"-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd"
>
<html>
<head>
<meta http-equiv=
"Content-Type"
content=
"text/html; charset=UTF-8"
>
<title>測試</title>
<script type=
"text/javascript"
src=
"../resources/js/jquery-1.11.1.min.js"
></script>
<script type=
"text/javascript"
>
$(
function
(){
//動態添加
$(
".add"
).on(
"click"
,
function
(){
console.log(
"進來了"
);
$(
".info"
).append(
'<div class="delete"><h3>單擊我來刪除我</h3></div>'
);
});
//對動態添加的元素添加事件-刪除
$(
".info"
).on(
"click"
,
".delete"
,
function
(){
console.log(
"進來了Delete!"
);
$(
this
).remove();
});
});
</script>
</head>
<body>
<h2 class=
'add'
>單擊我添加動態元素</h2>
<div class=
"info"
></div>
</body>
</html>
以上代碼就是本文對jquery append 動態添加的元素事件on 不起作用的解決方案,希望對大家學習有所幫助。