基于Selector Help的JQuery SlideUP和SlideDown

发布于 2024-11-18 01:24:56 字数 1711 浏览 3 评论 0原文

我正在自学 jQuery,并乐于尝试解决这个问题。我使用 slideDownslideUp 函数来让不同的

在需要时出现和消失。但我的问题在于删除。我可以让不同的选定选项单独显示,但是,如果当我尝试仅删除其中一个
时,同时显示两个
,两个
都快速闪烁,然后都消失。当仅显示一个
时也会发生这种情况。我单击删除链接,两个
快速闪烁,然后消失。我真的不知道为什么。该代码背后的想法是允许用户根据需要添加和删除。如果错误地做出了选择,用户将能够将其删除,而之前选择的其他选择仍然可见。这是我的代码:

<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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

牵强ㄟ 2024-11-25 01:24:56

您走在正确的道路上,我认为问题是您没有阻止链接的默认操作,因此页面正在刷新(导致您看到 divs 一下)。您可以通过接受 event 参数并对其调用 .preventDefault() 来阻止链接的默认操作,即:

$("#remove").click(function(e) {
    e.preventDefault();
    $("#loginselect").slideUp("slow");
});

这里正在工作: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 divs for a second). You can prevent the default action of a link by accepting an event parameter and calling .preventDefault() on it, i.e:

$("#remove").click(function(e) {
    e.preventDefault();
    $("#loginselect").slideUp("slow");
});

Here it is working: http://jsfiddle.net/XzDzb/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文