我正在使用帶有codeigniter的Ajax加載程序。 我正在用ajax加載另一個視圖,但即時通訊有一個問題,要將活動類添加到按下的按鈕。帶有Codeigniter的Ajax加載程序
這是Ajax腳本。 其此步驟旁邊工作
$(this).addClass('active');它消除了其它活性類按鈕,但不會插入到一個IM按壓
<script type="text/javascript">
$(document).ready(function(){
var baseurl = "<?php echo base_url() ?>";
//$('#submenu li a').click(function() {
//$('#submenu li').removeClass('active');
//$(this).addClass('active');
//});
// Ajax Slide & Fade Content with jQuery
$('.more').live('click',function(){
var href = $(this).attr('href');
if ($('#ajax').is(':visible')) {
$('#ajax').css('display','block').animate({height:'1px'}).empty();
}
$('#ajax').html('<img class="loader" src="'+baseurl+'assets/img/ajax-loader.gif" alt="">');
$('#ajax').css('display','block').animate({height:'500px'},function(){
$('#ajax').load(baseurl +'index.php/andreiaclinicaestetica/content #'+href,function(){
$('#ajax').hide().fadeIn();
$('#submenu li a').click(function() {
$('#submenu li').removeClass('active');
$(this).addClass('active');
});
});
});
return true;
});
});
</script>
這是被加載
<div class="content" id="page_01">
<h3>Lorem ipsum dolor</h3>
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Phasellus hendrerit. Pellentesque aliquet nibh nec urna. In nisi neque, aliquet vel, dapibus id, mattis vel, nisi. Sed pretium, ligula sollicitudin laoreet viverra, tortor libero sodales leo, eget blandit nunc tortor eu nibh. Nullam mollis. Ut justo. Suspendisse potenti.</p>
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Phasellus hendrerit. Pellentesque aliquet nibh nec urna. In nisi neque, aliquet vel, dapibus id, mattis vel, nisi. Sed pretium, ligula sollicitudin laoreet viverra, tortor libero sodales leo, eget blandit nunc tortor eu nibh. Nullam mollis. Ut justo. Suspendisse potenti.</p>
</div>
<div class="content" id="page_02">
<ul class="nav nav-tabs" id="submenu">
<li class="active"><a href="#">Corpo</a></li>
<li><a href="#">Rosto</a></li>
<li><a href="#">Depilação</a></li>
<li><a href="#">Maquilhagem</a></li>
<li><a href="#">Rádiofrequência Bipolar</a></li>
<li><a href="#">Spa</a></li>
</ul>
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Phasellus hendrerit. Pellentesque aliquet nibh nec urna. In nisi neque, aliquet vel, dapibus id, mattis vel, nisi. Sed pretium, ligula sollicitudin laoreet viverra, tortor libero sodales leo, eget blandit nunc tortor eu nibh. Nullam mollis. Ut justo. Suspendisse potenti.</p>
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Phasellus hendrerit. Pellentesque aliquet nibh nec urna. In nisi neque, aliquet vel, dapibus id, mattis vel, nisi. Sed pretium, ligula sollicitudin laoreet viverra, tortor libero sodales leo, eget blandit nunc tortor eu nibh. Nullam mollis. Ut justo. Suspendisse potenti.</p>
</div>
<div class="content" id="page_03">
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Phasellus hendrerit. Pellentesque aliquet nibh nec urna. In nisi neque, aliquet vel, dapibus id, mattis vel, nisi. Sed pretium, ligula sollicitudin laoreet viverra, tortor libero sodales leo, eget blandit nunc tortor eu nibh. Nullam mollis. Ut justo. Suspendisse potenti.</p>
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Phasellus hendrerit. Pellentesque aliquet nibh nec urna. In nisi neque, aliquet vel, dapibus id, mattis vel, nisi. Sed pretium, ligula sollicitudin laoreet viverra, tortor libero sodales leo, eget blandit nunc tortor eu nibh. Nullam mollis. Ut justo. Suspendisse potenti.</p>
</div>
<div class="content" id="page_04">
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Phasellus hendrerit. Pellentesque aliquet nibh nec urna. In nisi neque, aliquet vel, dapibus id, mattis vel, nisi. Sed pretium, ligula sollicitudin laoreet viverra, tortor libero sodales leo, eget blandit nunc tortor eu nibh. Nullam mollis. Ut justo. Suspendisse potenti.</p>
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Phasellus hendrerit. Pellentesque aliquet nibh nec urna. In nisi neque, aliquet vel, dapibus id, mattis vel, nisi. Sed pretium, ligula sollicitudin laoreet viverra, tortor libero sodales leo, eget blandit nunc tortor eu nibh. Nullam mollis. Ut justo. Suspendisse potenti.</p>
</div>
股利裝入主視圖DIV中的視圖ID = 「AJAX」。
即時通訊使用Codeigniter框架...一切運行良好旁邊(this).addclass將無法正常工作,但之前刪除類。由於
請請不住使用。 http://stackoverflow.com/questions/11115864/whats-wrong-with-the-jquery-live-method如果你閱讀live()上的文檔,你會發現它被棄用,甚至jQuery團隊建議你使用' delegate()'爲老版本的jQuery生效(其他所有使用on()方法) – rlemon 2012-07-23 12:05:22
爲什麼將術語codeigniter放置在標題中以及標籤內部,以及我根本不知道這與PHP有什麼關係。那麼你在問什麼? Codeiniter,PHP,jQuery,ajax? ?? – hakre 2012-07-23 12:08:38
我用的方法.on而不是.live,謝謝rlemon 而且,我沒有把標籤codeigniter,因爲它的框架即時通訊使用,內容是一個不同的視圖正在加載,槽ajax ..對不起,它第一次即時通訊使用stackoverflow問尋求幫助... – JonnyDevv 2012-07-23 17:57:26