Ora*_*ind 10 javascript php ajax jquery click
我正在使用jQuery使用$ .ajax(假设test.html)通过AJAX加载页面.
它是一个简单的HTML文档,在单击它们时会有一些按钮和相关的动画(也使用jQuery).
当我直接加载页面时,关联的.click()属性正常工作,但是当我在加载AJAX的版本中单击它们时,按钮无法响应.
由于我太过疲惫,无法解释我正在做的所有闷闷不乐,我只是在编写下面的所有代码,为此道歉.以下是文件中的必需代码.
<!-- p11.php -->
<!DOCTYPE html">
<html>
<head>
<title>jQuery</title>
<script type="text/javascript" src="c/js/jquery.js"></script>
<script type="text/javascript" src="c/js/jtry11.js"></script>
<link rel='stylesheet' type='text/css' href='c/css/css11.css'>
</head>
<body>
<button id="go1">Load Something Using AJAX</button>
<div id="msg"></div>
<div id="showButton">
<button id="showLoadedPage">Show the Page</button>
</div>
<div id="results"></div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
而下一个
$(document).ready(function()
{
$('#results').hide();
$('#msg').hide();
$('#showButton').hide();
$('#loading').hide();
$('#loaded').hide();
$('#load').live('click', function()
{
$('#load').hide();
$('#loading').show();
$('#msg').show('fast');
$.ajax({
url: 'test.html',
cache: false,
success: function(html) {
$('#results').append(html);
}
});
$('#msg').ajaxSuccess(function(evt, request, settings){
$(this).append('Click the Button Below to View the Page');
$('#showButton').show('slow');
$('#hideLoadedPage').hide();
$('#loading').hide();
$('#loaded').show();
});
});
$('#showLoadedPage').live('click', function() {
$('#loaded').hide('slow');
$('#msg').hide('slow');
$('#results').show('fast');
$('.shower').hide();
$(this).hide();
$('#hideLoadedPage').show();
});
$('#hideLoadedPage').live('click', function() {
$('#results').hide('fast');
$('.shower').hide();
$(this).hide();
$('#showLoadedPage').show();
});
$('.hider').live('click', function() {
$('.shower').show();
$(this).hide();
$('p.one').hide('slow');
$('p.two').hide('medium');
$('p.three').hide('fast');
});
$('.shower').live('click', function() {
$('.hider').show();
$(this).hide();
$('p.one').show('slow');
$('p.two').show('medium');
$('p.three').show('fast');
});
$('p.*').live('click', function() {
$(this).hide('slow');
if( $('p').is(':hidden') ) {
$('.shower').show();
}
if( $('p.*').is(':hidden') ) {
$('.hider').show();
}
});
});
Run Code Online (Sandbox Code Playgroud)
和最后一个
<!-- test.html -->
Page Loaded by Ajax.
Not the original Page
<center>
<button class="hider">
<img src="c/images/zoom_out.png" alt="zoom_out" />
Hide 'em
</button>
<button class="shower">
<img src="c/images/zoom_in.png" alt="zoom_out" />
Show it
</button>
<p class="one">Hiya</p>
<p class="two">Such interesting text, eh?</p>
<p class="three">The third Paragraph</p>
</center>
Run Code Online (Sandbox Code Playgroud)
我希望我没有犯很大的错误?
med*_*iev 26
听起来像你需要的
$('#go1').live('click', function() {});
Run Code Online (Sandbox Code Playgroud)
$ .fn.live,因为事件处理程序仅在初始dom创建时注册,并且您正在重新填充DOM并且没有附加.
更多信息@ http://docs.jquery.com/Events/live
| 归档时间: |
|
| 查看次数: |
18735 次 |
| 最近记录: |