If both sides of the text is empty, hidden text middle vertical line

 

 

Html

 

<p class="HiddenLine gray3">

<span>国有企业</span><span class="verticalLine">|</span>

<span>1001人以上</span><span class="verticalLine">|</span>

<Span class = "emptySpan"> <font> beverage manufacturers </ font> business </ span>

<span class="verticalLine">|</span><span>南宁</span></p>

 

Js

//emptySpan

                $(".emptySpan font").each(function () {

                    var _thisFont = $(this);

                    if ($.trim(_thisFont.text()) == "") {

                        _thisFont.parent().text("").css({ "width": 0, "height": 0, "overflow": "hidden" });

                    }

                });                

// hide '|'

                $(".HiddenLine").each(function () {

                    var $this = $(this);

                    var len = $this.find("span").length;

                    var firstSpanText = $.trim($this.find("span:eq(0)").text());

 

                    if (firstSpanText == "") {// If the first span is empty

                        for (var j = 0; j < len; j++) {

                            if ($.trim($this.find("span:eq(" + (j * 2) + ")").text()) == "") {

                                $this.find("span:eq(" + (j * 2 + 1) + ")").hide();

                            }

                        }

                    } Else {// the first span is not empty

                        for (var j = 1; j * 2 < len; j++) {

                            if ($.trim($this.find("span:eq(" + (j * 2) + ")").text()) == "") {

                                $this.find("span:eq(" + (j * 2 - 1) + ")").hide();

                            }

                        }

                    }

                });

Guess you like

Origin www.cnblogs.com/sunnywindycloudy/p/11646601.html