English 中文(简体)
从选中的选项机制中选择 jj 查询以切换
原标题:jQuery toggle select from select option mechanism

我试图通过一个选择选项来切换。 我很难切换超过两个选项。 我的目标是通过选择选项可以切换到 4 。 例如, 分类和子分类。 这是我在 < a href=" http://jsfiddle. net/ uA7XD/ 64" rel=“ no follow” >jsfidle 中的例子 。

<script type="text/javascript">
    var op = $("#tables option[value= options ]:selected");
    var os = $("#tables option[value= Example2 ]:selected");
    if (op.length)
        $("#something").show();
    else
        $("#something").hide();
    if (op == ("#something").show())
             $("#something2").show();
    else
        $("#something2").hide();

}​
</script>
最佳回答

这就是你要找的设计图案吗?

if your object is not selected
    if your parent is selected
        you are also selected
    else
        you are selected
else
    you are now unselected

这一逻辑将有利于任何深度的再现。

EDIT: Assuming each menu is a ul. You ll have to tweak the selectors. This is just one way to do it. Not the best if you have events firing on visibility, or if you have ui reflow issues.

clickyclicky = function(event) {
    var $target = $(event.currentTarget);
    if (!$target.hasClass("selected")) {
        // hide the old target and its parents
        var $oldTarget = $( .selected );
        $oldTarget.removeClass("selected").hide().parents( ul ).hide();
        // show the new target and its parents
        $target.show().addClass("selected").parents( ul ).show();
    } else {
        // hide the target
        $target.removeClass("selected").hide();
        // move the selected token to the parent.
        $parent = $target.parent().parent(); // assuming an ul/li tree pattern.
        if ($parent.is( ul )) {
            $parent.addClass("selected");
        }
    }
}

我测试过这个代码,只是一般参考

EDIT:这里的小问题:http://jsfiddle.net/ uA7XD/76/

问题回答

暂无回答




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签