【发布时间】:2015-04-21 04:53:10
【问题描述】:
我想使用 ajax 显示或隐藏数据 div
这里我的代码作为脚本工作,但我想像在 ajax 中一样加载。
如果点击下一个按钮,它会显示下一个 div。
然后你点击上一个按钮它会显示上一个 div。
我的脚本代码如下:
<script>
$('#next').click(function() {
$('.current').removeClass('current').hide()
.next().show().addClass('current');
if ($('.current').hasClass('last')) {
$('#next').attr('disabled', true);
}
$('#prev').attr('disabled', null);
});
$('#prev').click(function() {
$('.current').removeClass('current').hide()
.prev().show().addClass('current');
if ($('.current').hasClass('first')) {
$('#prev').attr('disabled', true);
}
$('#next').attr('disabled', null);
});
</script>
我的html代码如下:
<h1> QUESTIONS</h1>
<style>
#div{display:none;}
</style>
<button id="prev" disabled="disabled"> PREVIOUS </button>
<button id="next"> NEXT </button>
<form action="<?php echo site_url('pages/answers');?>" method="post">
<div id="main">
<?php $i=1;
$tt=$ques->num_rows();
foreach($ques->result() as $qus)
{ ?>
<div <?php if($i==1){?>id="div1" class="first current" <?php } else {?> id="div" <?php } if($i==$tt) {?> class="last"<?php }?>>
<input type="hidden" name="q_id[]" value="<?php echo $qus->qst_id; ?>"/>
<?php echo $i.') ' .$qus->qst_questions;?>
<label> <input type="radio" name="<?php echo $qus->qst_id;?>" value="A"/><?php echo $qus->qst_option_a; ?></label>
<label> <input type="radio" name="<?php echo $qus->qst_id;?>" value="B"/><?php echo $qus->qst_option_b; ?></label>
<label> <input type="radio" name="<?php echo $qus->qst_id;?>" value="C"/><?php echo $qus->qst_option_c; ?></label>
<label> <input type="radio" name="<?php echo $qus->qst_id;?>" value="D"/><?php echo $qus->qst_option_d; ?></label>
</div>
<?php $i++; }?>
</div>
</form>
这里使用 ajax 显示/隐藏 div。
怎么做?请帮助任何人解决我的问题。
这里举个例子['plese see this']
这是在脚本中加载的,但我想在 ajax 中加载
【问题讨论】:
-
您想通过 AJAX 加载内容,然后在选项卡中显示。对吗?
-
Tushar..你看到了上面的例子,我想在 ajax 中加载
-
@YuvarajUraj “加载 ajax”是什么意思?你需要在ajax中加载div的内容吗?
标签: javascript jquery html ajax