【发布时间】:2014-02-01 00:17:36
【问题描述】:
1.这是我的代码,我有一个 div 类内部,它使用 ajax 调用动态加载 在ajax调用之后,如果我点击隐藏按钮,它就不起作用了。
但它在 ajax 请求之前工作得很好。
所以为了克服我只是添加一个外部 div 并隐藏该 div 这次它可以工作.. 不知道为什么?
$( "#inner" ).replaceWith( data ); /*and*/ $( "#inner" ).hide(); //not working
$( "#inner" ).replaceWith( data ); /*and*/ $( "#outer" ).hide(); //working
为什么我们不能使用同一个 div 类?
<html>
<div id="outer">
<div id="inner">
<br /> <br /> <br />
<div> <input type="button" value="signup" onclick="changeval();"/>
</div>
<br /> <br />
</div>
</div>
<input type="button" value="hide" onclick="onhide();"/>
<script language="javascript">
function changeval(context)
{
var typeval="sdsf";
var url="sdfsdf";
$.ajax({
type:'POST',
url:'htp://sscs/registration',
data:'&typeval='+typeval+'&url='+url,
success:function(data) {
$( "#inner" ).replaceWith( data );
}
});
}
function onhide()
{
$( "#inner" ).hide();
}
</script>
【问题讨论】:
-
尝试使用 $("#inner").replaceWith($('#inner',data));
-
尝试 .html() 而不是 replaceWith()
-
是的,它起作用了,但我想知道为什么当我们使用替换时它不起作用
标签: javascript jquery html ajax