基于Selector Help的JQuery SlideUP和SlideDown
我正在自学 jQuery,并乐于尝试解决这个问题。我使用 slideDown
和 slideUp
函数来让不同的
在需要时出现和消失。但我的问题在于删除。我可以让不同的选定选项单独显示,但是,如果当我尝试仅删除其中一个
时,同时显示两个
,两个
都快速闪烁,然后都消失。当仅显示一个
时也会发生这种情况。我单击删除链接,两个
快速闪烁,然后消失。我真的不知道为什么。该代码背后的想法是允许用户根据需要添加和删除。如果错误地做出了选择,用户将能够将其删除,而之前选择的其他选择仍然可见。这是我的代码:<div class="type-select" style="width:400px;">
<select name="selectStatus">
<option selected value="Select">Select...</option>
<option id="login">Login</option>
<option id="nav">Navigation</option>
</select></div>
<div id="loginselect"><img src="http://triplemsystems.ekkosolutions.com/images/global/bg-loginPages.gif" height="47" width="162" />
<a id="remove" href="">Remove</a></div>
<div id="navselect"><img src="http://triplemsystems.ekkosolutions.com/images/global/bg-navMain.gif" height="45" width="90"/>
<a id="removenav" href="">Remove</a></div>
<script>
$("#loginselect").hide("fast");
$("select").change(function(){
if($("#login").is(":selected")){
$("#loginselect").slideDown("slow");}
});
$("#remove").click(function() {
$("#loginselect").slideUp("slow");
});
$("#navselect").hide("fast");
$("select").change(function () {
if($("#nav").is(":selected")){
$("#navselect").slideDown("slow");}
});
$("#removenav").click(function() {
$("#navselect").slideUp("slow");});
</script>
我走在正确的道路上吗?
I'm teaching myself jQuery and having fun trying to figure this out. I'm using the slideDown
and slideUp
functions to have different <div>
's appear and disappear if needed. But my problem is in the removal. I can get the different selected options to appear separately, however, if both <div>
's are showing when I try to remove just one of the <div>
's, both <div>
's flash quickly and then both disappear. It also happens when only one of the <div>
's is showing too. I click the remove link and both <div>
's flash quickly and then disappear. I really haven't got a clue as to why. The idea behind this code is to allow a user to add to and take away as needed. If a selection was made in mistake, the user would be able to remove it while the other selections that were previously selected stay visible. Here's my code:
<div class="type-select" style="width:400px;">
<select name="selectStatus">
<option selected value="Select">Select...</option>
<option id="login">Login</option>
<option id="nav">Navigation</option>
</select></div>
<div id="loginselect"><img src="http://triplemsystems.ekkosolutions.com/images/global/bg-loginPages.gif" height="47" width="162" />
<a id="remove" href="">Remove</a></div>
<div id="navselect"><img src="http://triplemsystems.ekkosolutions.com/images/global/bg-navMain.gif" height="45" width="90"/>
<a id="removenav" href="">Remove</a></div>
<script>
$("#loginselect").hide("fast");
$("select").change(function(){
if($("#login").is(":selected")){
$("#loginselect").slideDown("slow");}
});
$("#remove").click(function() {
$("#loginselect").slideUp("slow");
});
$("#navselect").hide("fast");
$("select").change(function () {
if($("#nav").is(":selected")){
$("#navselect").slideDown("slow");}
});
$("#removenav").click(function() {
$("#navselect").slideUp("slow");});
</script>
Am I even on the right path?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您走在正确的道路上,我认为问题是您没有阻止链接的默认操作,因此页面正在刷新(导致您看到
divs 一下)。您可以通过接受
event
参数并对其调用.preventDefault()
来阻止链接的默认操作,即:这里正在工作:http://jsfiddle.net/XzDzb/
You are on the right path, I think the problem is that you are not preventing the default action of the links, and so the page is being refreshed (causing you to see the
div
s for a second). You can prevent the default action of a link by accepting anevent
parameter and calling.preventDefault()
on it, i.e:Here it is working: http://jsfiddle.net/XzDzb/