jquery动态添加元素,报错.请问这个问题怎么处理

如题所述

具体错误具体分析,一般碰到问题先看是在哪一行代码出现了错误,然后在这段代码附件打断点调试,发现问题,才能解决问题。
温馨提示:内容为网友见解,仅供参考
第1个回答  2015-12-02
在控制台看看具体报什么错,然后搜素一下就知道了!
第2个回答  2015-12-02
什么错误??内容呢?
第3个回答  2015-12-02
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script class="jquery library" src="/js/sandbox/jquery/jquery-1.8.2.min.js" type="text/javascript"></script>
<title>
RunJS 演示代码
</title>
<style type="text/css">
.row{
width:200px;
height:<a href="https://www.baidu.com/s?wd=500px&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1dBmHn3nvfkPj--uhuhmhwb0AP8IA3qPjfsn1bkrjKxmLKz0ZNzUjdCIZwsrBtEXh9GuA7EQhF9pywdQhPEUiqkIyN1IA-EUBtznWmLP1cvPjfLPWbdrH0dPH03" target="_blank" class="baidu-highlight">500px</a>;
background: yellow;
}
.one{
width:200px;
height:50px;
background: green;
}
</style>
<script type="text/javascript">
var str ="<div class='one' style='<a href="https://www.baidu.com/s?wd=font-weight&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1dBmHn3nvfkPj--uhuhmhwb0AP8IA3qPjfsn1bkrjKxmLKz0ZNzUjdCIZwsrBtEXh9GuA7EQhF9pywdQhPEUiqkIyN1IA-EUBtznWmLP1cvPjfLPWbdrH0dPH03" target="_blank"class="baidu-highlight">font-weight</a>:bold;'><span>新添加的元素删除</span></div>";
$(document).ready(function(){
$("button").click(function(){
$(".row").append(str);
});
$(".row").delegate("span","click",function(){
$(this).closest("div").remove();
});
});
</script>
</head>
<body>
<button id='add'>
新增元素
</button>
<div class="row">
<div class="one">
<span>
删除
</span>
</div>
<div class="one">
<span>
删除
</span>
</div>
</div>
</body>
</html>
相似回答
大家正在搜