隐藏上一个输入按钮
我有执行循环的 php 代码,在循环中生成以下内容:
echo "<input type=\"button\" event='$eventID' id=\"sendsomeone\" value=\"Send a family member\"/>";
echo "<span id='$eventID'></span>";
后来,我有如下的 javascript:
$('input:button').click(function() {
$(this).next("span").append('You clicked this button!');
}
这段代码工作正常。但我希望它也隐藏按钮(但不是页面上的所有按钮)
我尝试过使用类似
$(this).parent("input").hide();
和 $(this).prev(" input").hide();
但我无法弄清楚如何使其工作。
I have php code which executes a loop, inside which it generates the following:
echo "<input type=\"button\" event='$eventID' id=\"sendsomeone\" value=\"Send a family member\"/>";
echo "<span id='$eventID'></span>";
Later, I have javascript which follows:
$('input:button').click(function() {
$(this).next("span").append('You clicked this button!');
}
This code works fine. But I want it to also hide the button (but not all the buttons on the page)
I've tried fooling with code like
$(this).parent("input").hide();
and $(this).prev("input").hide();
But I can't puzzle out how to make it work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看起来您已经使用
$('input:button')
进入了按钮选择器,那么您尝试过这样做吗?It looks like you're already in the buttons selector by using
$('input:button')
, so have you tried doing this?您可能还想查看 toggle 这很有帮助,因为如果它可见,它会隐藏它,并显示如果不是:
You might also want to look at toggle which is helpful as it swill hide it if it's visible, and show it if it's not: