想知道我刪除后為什么不能添加
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title></title>
<style>
</style>
<script src="http://idcbgp.cn/static/lib/jquery/1.9.1/jquery.js"></script>
</head>
<body>
<div id="second">I am fine.</div>
<button>點(diǎn)擊清除</button>
<button id="try">點(diǎn)擊添加</button>
<script>
$(function(){
var s
$("button:first").click(function(){
var s=$("#second").detach()
})
$("#try").click(function(){
$("body").prepend(s)
})
})
</script>
</body>
</html>
2019-05-06
把?
改成?
就好了。因?yàn)樵邳c(diǎn)擊事件外已經(jīng)定義了全局變量s,點(diǎn)擊事件里又定義了一個(gè)s,這里的是局部變量,給這個(gè)局部變量賦值,并不能作用于全局變量。所以添加不了。
望采納