English 中文(简体)
热量动力加/微粒
原标题:Jquery dynamic plus/minus symbol toggle

I m 采用jquery toggle script。 我真的希望有一个加(+)的标志,在角逐点开始的时候,在标题中显示,如果是,则显示(-)的符号。

我之所以这样说,不仅仅是使用以下文字,是因为当另一个角点被点击时,目前使用的手稿Im自动接近打开的角,而这正是我真正喜欢的一个特征:

$( #toggle-view li ).click(function () {

    var text = $(this).children( p );

    if (text.is( :hidden )) {
        text.slideDown( 200 );
        $(this).children( span ).html( - );     
    } else {
        text.slideUp( 200 );
        $(this).children( span ).html( + );     
    }   
});
});

我使用的是:

$(document).ready(function(){
$(".parents-toggle > div").click(function () {
$(".parents-toggle > div.iteminfo-toggle").not($(this).siblings()).slideUp();
$(this).siblings(".iteminfo-toggle").slideToggle();
});
});

页: 1

<div class="parents-toggle">
<div class="itemheading2_toggle">Heading</div>
<div class="iteminfo-toggle hidden">
text goes here
</div>

没有人会想如何把加/红外标志结合到我使用的目前文字中?

http://www.queness.com/resources/html/toggle/index.html

最佳回答

这里我是怎样做的:

var parent = $( #toggle-view ), // storing main ul for use below
    delay = 200; // storing delay for easier configuration

// bind the click to all headers
$( li h3 , parent).click(function() {

    // get the li that this header belongs to
    var li = $(this).closest( li );

    // check to see if this li is not already being displayed
    if (!$( p , li).is( :visible ))
    {
        // loop on all the li elements
        $( li , parent).each(function() {

            // slide up the element and set it s marker to  +  
            $( p , $(this)).slideUp(delay);
            $( span , $(this)).text( + );
        });

        // display the current li with a  -  marker
        $( p , li).slideDown(delay);
        $( span , li).text( - );
    }
});

Check out http://jsfiddle.net/v9Evw/ to see it in action.


在点击上躲藏,如果它目前看得见的话,在点击方法上添加一个其他内容:

    else {
        $( p , li).slideUp(delay);
        $( span , li).text( + );  
    }

http://jsfiddle.net/v9Evw/1/“rel=“nofollow”) http://jsfiddle.net/v9 Evw/1/,以了解最新情况。

问题回答

How about this?

html:添加一个编号的序号

<div class="parents-toggle">
    <div class="itemheading2_toggle"><span class="symbol">-</span>Heading</div>
<div class="iteminfo-toggle hidden">
text goes here
</div>

js: toggle +/- 文号

$(".parents-toggle > div").click(function () {
    $(".parents-toggle > div.iteminfo-toggle").not($(this).siblings()).slideUp();
    $(this).siblings(".iteminfo-toggle").slideToggle();

    // toggle open/close symbol
    if($( .itemheading2_toggle span ).text() ==  - ){
        $( .itemheading2_toggle span ).text( + );   
    } else {
        $( .itemheading2_toggle span ).text( - );
    }
});

Demo:

If you used fontawesome or any other web icons, you could take advantage of jQuery s hasClass and add/remove class functions. I prefer this because the code looks cleaner.

I prefer carets instead of plus-minus. You can use fa-plus fa-minus instead

<script>
$( .reveal1 ).click(function(){
    $( .optional-field1 ).toggle(200);
    
    var child = $(this).children();
    if(child.hasClass( fa-caret-down ))
        child.removeClass( fa-caret-down ).addClass( fa-caret-up );
    else
        child.removeClass( fa-caret-up ).addClass( fa-caret-down );

    return false;
});
</script>
<link href="https://use.fontawesome.com/releases/v5.1.0/css/all.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<a class="reveal1" href="#">Toggle Expand <i class="fa fa-caret-down"></i></a>

<p class="optional-field1" style="display: none;">
  Lorem Ipsum is simply dummy text
</p




相关问题
getGridParam is not a function

The HTML: <a href="javascript:void(0)" id="m1">Get Selected id s</a> The Function: jQuery("#m1").click( function() { var s; s = jQuery("#list4").getGridParam( selarrrow )...

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.

jQuery cycle page with links

I am using the cycle plugin with pager functionality like this : $j( #homebox ) .cycle({ fx: fade , speed: fast , timeout: 9000, pager: #home-thumbs , ...

jquery ui dialog opens only once

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.

jConfirm with this existing code

I need help to use jConfirm with this existing code (php & Jquery & jAlert). function logout() { if (confirm("Do you really want to logout?")) window.location.href = "logout.php"; } ...

Wrap text after particular symbol with jQuery

What I m trying to do, is wrap text into div inside ll tag. It wouldn t be a problem, but I need to wrap text that appears particularly after "-" (minus) including "minus" itself. This is my html: &...

热门标签