我有一个包含两个表的数据库,每个表都有三行,并且都通过id连接。我在.php中执行了它们,以便table_1(question)中的每一行在table_2(answers)中都有其答复。
现在,我试图将SLIDEUP / SLIDEDOWN函数放到按钮触发的答案中。
但是不幸的是缺少一些东西...
我的代码如下:
<div id="a" name="a">
<small><p><?php echo $row2["date"]; ?></p></small>
<p><B><big><font color= #ba4a00> A:</font></B></big> <small><?php echo $row2["answer"]; ?></small></br></p>
</div>
<button class="btn1">Slide up</button>
<button class="btn2">Slide down</button>
<script type='text/javascript'>
src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js">
</script>
<script>
$(document).ready(function(){
$(".btn2").click(function(e){
e.preventDefault();
$('[name="a"]').slideDown();
$(this).parent().$('[name="a"]').slideDown();
$(this).hide();
});
$(".btn1").click(function(e){
e.preventDefault();
$(this).parent().$('[name="a"]').slideUp();
$(this).hide();
});
});
</script>
最佳答案
如果打开Web控制台,则会在其中看到有关尝试将undefined
作为函数调用的错误,原因是:
$(this).parent().$('[name="a"]').slideDown();
$(this).parent()
返回一个jQuery对象。 jQuery对象没有$
属性。你可能是说
$(this).parent().find('[name="a"]').slideDown();
旁注:从代码来看,在我看来,包含div和按钮的此结构在页面上重复了多次。如果是这样,则需要删除div上的
id="a"
,因为不能在多个元素上使用相同的ID。关于javascript - jQuery Slide函数完全不表现数据库中的数据,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/39345832/