使用JQuery选择缩进的非子项

时间:2017-09-22 04:04:47

标签: jquery html

假设我有一些这样的代码:

Rows

假设我想创建一个jQuery来检测当我点击ol.settings元素中的list元素时,然后直接切换它下面的p.explanation:

import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;

import java.awt.Color;
import javax.swing.border.LineBorder;
import javax.swing.JLabel;
import javax.swing.JOptionPane;

import java.awt.Font;
import java.awt.Graphics2D;
import java.io.File;
import java.io.FileOutputStream;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.swing.SwingConstants;
import javax.swing.UIManager;
import javax.swing.border.TitledBorder;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartFrame;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.labels.StandardCategoryItemLabelGenerator;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.StackedBarRenderer;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.data.general.DefaultPieDataset;

import com.alee.laf.WebLookAndFeel;
import com.itextpdf.awt.DefaultFontMapper;
import com.itextpdf.text.BaseColor;
import com.itextpdf.text.Document;
import com.itextpdf.text.Element;
import com.itextpdf.text.FontFactory;
import com.itextpdf.text.Image;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.Phrase;
import com.itextpdf.text.Rectangle;
import com.itextpdf.text.pdf.ColumnText;
import com.itextpdf.text.pdf.PdfContentByte;
import com.itextpdf.text.pdf.PdfPCell;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfTemplate;
import com.itextpdf.text.pdf.PdfWriter;
import com.toedter.calendar.JDateChooser;
import javax.swing.JButton;
import javax.swing.ImageIcon;
import java.awt.event.ActionListener;
import java.awt.geom.Rectangle2D;
import java.awt.event.ActionEvent;

public class SalesReport {

    private JFrame frmSalesReport;
    private static Connection con;
    private PreparedStatement PStat;
    private ResultSet res;
    private String query;
    private String Grand,totalpaid,paydue;
    private Double grand,grandtotal=0.0,Total_paid,tot_Paid=0.0,PayDue,Pay_Due=0.0;
    private JDateChooser ToDate,FromDate;

    /**
     * Launch the application.
     */
    public static void main(String\[\] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    SalesReport window = new SalesReport();
                    window.frmSalesReport.setVisible(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

    /**
     * Create the application.
     */
    public SalesReport() {
        initialize();
        con=CompanyInfo.Database();
    }

    public void GenerateReport()
    {
        try
        {
            Document document=new Document();       
            PdfWriter writer=PdfWriter.getInstance(document,new FileOutputStream("SalesReport.pdf"));       
            document.open();

            PdfContentByte canvas=writer.getDirectContent();

            Rectangle rect=new Rectangle(1,715,600,841);//left,bottom,right,top
            rect.setBorder(Rectangle.BOX);
            rect.setBackgroundColor(new BaseColor(31,155,118));
            rect.setBorderWidth(2);
            rect.setBorderColor(new BaseColor(31,155,118));
            canvas.rectangle(rect);

            String imagename="C:/Users/Mdazaz/workspace/InventorySystem/Images/index3.jpg";
            Image img=Image.getInstance(imagename);
            img.scaleToFit(100, 100);
            img.setAbsolutePosition(80, 730);
            canvas.addImage(img);


            String Title="ABC Pvt. Ltd.";
            Paragraph paraTitle=new Paragraph(Title,FontFactory.getFont(FontFactory.TIMES_BOLDITALIC,14,Font.BOLD,BaseColor.WHITE));
            paraTitle.setAlignment(Element.ALIGN_CENTER);

            String Address="356/3 Malviaya Nagar Near Khatushiyam Mandir Indore";
            Paragraph paraAddress=new Paragraph(Address,FontFactory.getFont(FontFactory.TIMES_BOLDITALIC,14,Font.BOLD,BaseColor.WHITE));            
            paraAddress.setAlignment(Element.ALIGN_CENTER);

            String Contact="Contact No.=7030456328";
            Paragraph paraContact=new Paragraph(Contact,FontFactory.getFont(FontFactory.TIMES_BOLDITALIC,14,Font.BOLD,BaseColor.WHITE));            
            paraContact.setAlignment(Element.ALIGN_CENTER);

            String Email="Email ID: mohammadazaz966@gmail.com";
            Paragraph paraEmail=new Paragraph(Email,FontFactory.getFont(FontFactory.TIMES_BOLDITALIC,14,Font.BOLD,BaseColor.WHITE));            
            paraEmail.setAlignment(Element.ALIGN_CENTER);

            ColumnText column=new ColumnText(canvas);
            column.setSimpleColumn(200,840,454,720);
            column.addElement(paraTitle);
            column.addElement(paraAddress);
            column.addElement(paraContact);
            column.addElement(paraEmail);
            column.go();

            Date date=new Date();
            Paragraph paradate=new Paragraph(date.toString(),FontFactory.getFont(FontFactory.TIMES_BOLDITALIC,14,Font.BOLD,BaseColor.BLACK));           
            paradate.setAlignment(Element.ALIGN_CENTER);

            Rectangle footer=new Rectangle(1,1,594,50);//left,bottom,right,top
            footer.setBorder(Rectangle.BOX);
            footer.setBackgroundColor(new BaseColor(31,155,118));
            footer.setBorderWidth(2);
            footer.setBorderColor(new BaseColor(31,155,118));
            canvas.rectangle(footer);

            String page="Page Number: "+String.valueOf(writer.getPageNumber());
            Paragraph parapage=new Paragraph(page,FontFactory.getFont(FontFactory.TIMES_BOLDITALIC,14,Font.BOLD,BaseColor.WHITE));          
            parapage.setAlignment(Element.ALIGN_CENTER);

            ColumnText columnFooter=new ColumnText(canvas);
            columnFooter.setSimpleColumn(footer);
            columnFooter.addElement(parapage);
            columnFooter.go();

            DateFormat year=new SimpleDateFormat("yyyy");
            String fromyear=year.format(FromDate.getDate());
            String toyear=year.format(ToDate.getDate());

            int fyear=Integer.parseInt(fromyear);
            int tyear=Integer.parseInt(toyear);

            Date date1=FromDate.getDate();
            Date date2=ToDate.getDate();
            String fromDate=DateFormat.getDateInstance().format(date1);//((JTextField)FromDate.getDateEditor().getUiComponent()).getText();
            String toDate=DateFormat.getDateInstance().format(date2);//((JTextField)FromDate.getDateEditor().getUiComponent()).getText();

            int serialNo=1;

            PdfPTable table=new PdfPTable(7);
            table.setSplitLate(false);
            PdfPCell Data=new PdfPCell();
            table.setWidthPercentage(110);

            String serialno="Serial No";
            Data=new PdfPCell(new Phrase(serialno,FontFactory.getFont(FontFactory.TIMES_BOLDITALIC,10,Font.BOLD,BaseColor.WHITE)));
            Data.setBackgroundColor(BaseColor.DARK_GRAY);
            Data.setHorizontalAlignment(Element.ALIGN_CENTER);
            Data.setVerticalAlignment(Element.ALIGN_MIDDLE);
            Data.setFixedHeight(30f);
            Data.setBorderWidth(1);
            table.addCell(Data);

            String Invoice="Invoice No";
            Data=new PdfPCell(new Phrase(Invoice,FontFactory.getFont(FontFactory.TIMES_BOLDITALIC,10,Font.BOLD,BaseColor.WHITE)));
            Data.setBackgroundColor(BaseColor.DARK_GRAY);
            Data.setHorizontalAlignment(Element.ALIGN_CENTER);
            Data.setVerticalAlignment(Element.ALIGN_MIDDLE);
            Data.setFixedHeight(30f);
            Data.setBorderWidth(1);
            table.addCell(Data);

            String InvoiceDate="Invoice Date";
            Data=new PdfPCell(new Phrase(InvoiceDate,FontFactory.getFont(FontFactory.TIMES_BOLDITALIC,10,Font.BOLD,BaseColor.WHITE)));
            Data.setBackgroundColor(BaseColor.DARK_GRAY);
            Data.setHorizontalAlignment(Element.ALIGN_CENTER);
            Data.setVerticalAlignment(Element.ALIGN_MIDDLE);
            Data.setFixedHeight(30f);
            Data.setBorderWidth(1);
            table.addCell(Data);

            String Cname="Customer Name";
            Data=new PdfPCell(new Phrase(Cname,FontFactory.getFont(FontFactory.TIMES_BOLDITALIC,10,Font.BOLD,BaseColor.WHITE)));
            Data.setBackgroundColor(BaseColor.DARK_GRAY);
            Data.setHorizontalAlignment(Element.ALIGN_CENTER);
            Data.setVerticalAlignment(Element.ALIGN_MIDDLE);
            Data.setFixedHeight(30f);
            Data.setBorderWidth(1);
            table.addCell(Data);

            String GrandTotal="Grand Total";
            Data=new PdfPCell(new Phrase(GrandTotal,FontFactory.getFont(FontFactory.TIMES_BOLDITALIC,10,Font.BOLD,BaseColor.WHITE)));
            Data.setBackgroundColor(BaseColor.DARK_GRAY);
            Data.setHorizontalAlignment(Element.ALIGN_CENTER);
            Data.setVerticalAlignment(Element.ALIGN_MIDDLE);
            Data.setFixedHeight(30f);
            Data.setBorderWidth(1);
            table.addCell(Data);


            String TotalPaid="Total Paid";
            Data=new PdfPCell(new Phrase(TotalPaid,FontFactory.getFont(FontFactory.TIMES_BOLDITALIC,10,Font.BOLD,BaseColor.WHITE)));
            Data.setBackgroundColor(BaseColor.DARK_GRAY);
            Data.setHorizontalAlignment(Element.ALIGN_CENTER);
            Data.setVerticalAlignment(Element.ALIGN_MIDDLE);
            Data.setFixedHeight(30f);
            Data.setBorderWidth(1);
            table.addCell(Data);

            String Balance="Balance";
            Data=new PdfPCell(new Phrase(Balance,FontFactory.getFont(FontFactory.TIMES_BOLDITALIC,10,Font.BOLD,BaseColor.WHITE)));
            Data.setBackgroundColor(BaseColor.DARK_GRAY);
            Data.setHorizontalAlignment(Element.ALIGN_CENTER);
            Data.setVerticalAlignment(Element.ALIGN_MIDDLE);
            Data.setFixedHeight(30f);
            Data.setBorderWidth(1);
            table.addCell(Data);

            String CGtot="   Grand Total :";
            Paragraph paraCGtot=new Paragraph(CGtot,FontFactory.getFont(FontFactory.TIMES_BOLDITALIC,12,Font.BOLD,BaseColor.BLACK));            
            paraCGtot.setAlignment(Element.ALIGN_LEFT);

            String CTotpaid="   Total Paid :";
            Paragraph paraCTotpaid=new Paragraph(CTotpaid,FontFactory.getFont(FontFactory.TIMES_BOLDITALIC,12,Font.BOLD,BaseColor.BLACK));          
            paraCTotpaid.setAlignment(Element.ALIGN_LEFT);

            String Cbalance="   Balance :";
            Paragraph paraCbalance=new Paragraph(Cbalance,FontFactory.getFont(FontFactory.TIMES_BOLDITALIC,12,Font.BOLD,BaseColor.BLACK));          
            paraCbalance.setAlignment(Element.ALIGN_LEFT);

            Rectangle RecColFoot2=new Rectangle(570,80,350,148);//left,bottom,right,top
            RecColFoot2.setBorder(Rectangle.BOX);
            RecColFoot2.setBackgroundColor(BaseColor.WHITE);
            RecColFoot2.setBorderWidth(2);
            RecColFoot2.setBorderColor(BaseColor.BLACK);
            canvas.rectangle(RecColFoot2);

            ColumnText columnFoot2=new ColumnText(canvas);
            columnFoot2.setSimpleColumn(RecColFoot2);
            columnFoot2.addElement(paraCGtot);
            columnFoot2.addElement(paraCTotpaid);
            columnFoot2.addElement(paraCbalance);
            columnFoot2.go();

            Rectangle RecColFoot3=new Rectangle(450,83,567,145);//left,bottom,right,top
            RecColFoot3.setBorder(Rectangle.BOX);
            RecColFoot3.setBackgroundColor(BaseColor.WHITE);
            RecColFoot3.setBorderWidth(2);
            RecColFoot3.setBorderColor(BaseColor.WHITE);
            canvas.rectangle(RecColFoot3);

            ColumnText columnDatafOOT=new ColumnText(canvas);
            columnDatafOOT.setSimpleColumn(RecColFoot3);

            DefaultCategoryDataset myBardataset = new DefaultCategoryDataset();


            query="Select * from BillingCustomer where In_Date>='"+fromDate+"' OR In_Date<='"+toDate+"'";
            PStat=con.prepareStatement(query);
            res=PStat.executeQuery();
            while(res.next())
            {
                Grand=res.getString("G_Tot");
                grand=Double.parseDouble(Grand);
                grandtotal=grandtotal+grand;

                totalpaid=res.getString("Tot_Pay");
                Total_paid=Double.parseDouble(totalpaid);
                tot_Paid=tot_Paid+Total_paid;

                paydue=res.getString("Pay_Due");
                PayDue=Double.parseDouble(paydue);
                Pay_Due=Pay_Due+PayDue;

                String serialNum=Integer.toString(serialNo);
                Data=new PdfPCell(new Phrase(serialNum,FontFactory.getFont(FontFactory.TIMES_ITALIC,11,Font.ITALIC,BaseColor.BLACK)));
                Data.setFixedHeight(30f);
                Data.setBorderWidth(1);
                Data.setHorizontalAlignment(Element.ALIGN_CENTER);
                Data.setVerticalAlignment(Element.ALIGN_MIDDLE);
                table.addCell(Data);
                serialNo++;

                String InvoiceNo=res.getString("In_Code");
                Data=new PdfPCell(new Phrase(InvoiceNo,FontFactory.getFont(FontFactory.TIMES_ITALIC,11,Font.ITALIC,BaseColor.BLACK)));
                Data.setFixedHeight(30f);
                Data.setBorderWidth(1);
                Data.setHorizontalAlignment(Element.ALIGN_CENTER);
                Data.setVerticalAlignment(Element.ALIGN_MIDDLE);
                table.addCell(Data);

                String Invoicedate=res.getString("In_Date");
                Data=new PdfPCell(new Phrase(Invoicedate,FontFactory.getFont(FontFactory.TIMES_ITALIC,11,Font.ITALIC,BaseColor.BLACK)));
                Data.setFixedHeight(30f);
                Data.setBorderWidth(1);
                Data.setHorizontalAlignment(Element.ALIGN_CENTER);
                Data.setVerticalAlignment(Element.ALIGN_MIDDLE);
                table.addCell(Data);

                String CName=res.getString("C_Name");
                Data=new PdfPCell(new Phrase(CName,FontFactory.getFont(FontFactory.TIMES_ITALIC,11,Font.ITALIC,BaseColor.BLACK)));
                Data.setFixedHeight(30f);
                Data.setBorderWidth(1);
                Data.setHorizontalAlignment(Element.ALIGN_CENTER);
                Data.setVerticalAlignment(Element.ALIGN_MIDDLE);
                table.addCell(Data);

                Data=new PdfPCell(new Phrase(Grand,FontFactory.getFont(FontFactory.TIMES_ITALIC,11,Font.ITALIC,BaseColor.BLACK)));
                Data.setFixedHeight(30f);
                Data.setBorderWidth(1);
                Data.setHorizontalAlignment(Element.ALIGN_CENTER);
                Data.setVerticalAlignment(Element.ALIGN_MIDDLE);
                table.addCell(Data);

                Data=new PdfPCell(new Phrase(totalpaid,FontFactory.getFont(FontFactory.TIMES_ITALIC,11,Font.ITALIC,BaseColor.BLACK)));
                Data.setFixedHeight(30f);
                Data.setBorderWidth(1);
                Data.setHorizontalAlignment(Element.ALIGN_CENTER);
                Data.setVerticalAlignment(Element.ALIGN_MIDDLE);
                table.addCell(Data);

                String CPayDue=res.getString("Pay_Due");
                Data=new PdfPCell(new Phrase(CPayDue,FontFactory.getFont(FontFactory.TIMES_ITALIC,11,Font.ITALIC,BaseColor.BLACK)));
                Data.setFixedHeight(30f);
                Data.setBorderWidth(1);
                Data.setHorizontalAlignment(Element.ALIGN_CENTER);
                Data.setVerticalAlignment(Element.ALIGN_MIDDLE);
                table.addCell(Data);            

            }
            myBardataset.setValue(new Double(grandtotal), "Total Sales", Integer.toString(fyear));

            Paragraph paraCG_Tot=new Paragraph(Double.toString(grandtotal),FontFactory.getFont(FontFactory.TIMES_BOLDITALIC,12,Font.BOLD,BaseColor.BLACK));         
            paraCG_Tot.setAlignment(Element.ALIGN_LEFT);
            columnDatafOOT.addElement(paraCG_Tot);
            columnDatafOOT.go();

            Paragraph paraCTot_Pay=new Paragraph(Double.toString(tot_Paid),FontFactory.getFont(FontFactory.TIMES_BOLDITALIC,12,Font.BOLD,BaseColor.BLACK));         
            paraCTot_Pay.setAlignment(Element.ALIGN_LEFT);
            columnDatafOOT.addElement(paraCTot_Pay);
            columnDatafOOT.go();

            Paragraph paraCPay_Due=new Paragraph(Double.toString(Pay_Due),FontFactory.getFont(FontFactory.TIMES_BOLDITALIC,12,Font.BOLD,BaseColor.BLACK));          
            paraCPay_Due.setAlignment(Element.ALIGN_LEFT);
            columnDatafOOT.addElement(paraCPay_Due);
            columnDatafOOT.go();

            ColumnText columnTable=new ColumnText(writer.getDirectContent());
            columnTable.setSimpleColumn(50,380,544,170);
            columnTable.addElement(table);
            columnTable.go();

            JFreeChart barchart=ChartFactory.createBarChart("Total Sales/Year", "Years", "Total Sales", myBardataset,PlotOrientation.VERTICAL,false,true,false);
            CategoryPlot plot=barchart.getCategoryPlot();
            plot.setRangeGridlinePaint(Color.black);
            StackedBarRenderer renderer=new StackedBarRenderer(false);
            renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
            renderer.setBaseItemLabelsVisible(true);
            renderer.setBaseItemLabelFont(new Font("Calibri",Font.BOLD,18));
            barchart.getCategoryPlot().setRenderer(renderer);
            renderer.setDrawBarOutline(false);
            renderer.setSeriesPaint(0, Color.decode("#84002E"));
            renderer.setBaseItemLabelPaint(Color.white);

            Rectangle bar=new Rectangle(60,650,330,410);//left,bottom,right,top
            bar.setBorder(Rectangle.BOX);
            bar.setBackgroundColor(BaseColor.WHITE);
            bar.setBorderWidth(2);
            bar.setBorderColor(BaseColor.BLACK);
            canvas.rectangle(bar);

            Rectangle fromdate=new Rectangle(50,700,550,670);//left,bottom,right,top
            fromdate.setBorder(Rectangle.BOX);
            fromdate.setBackgroundColor(new BaseColor(31,155,118));
            fromdate.setBorderWidth(2);
            fromdate.setBorderColor(new BaseColor(31,155,118));
            canvas.rectangle(fromdate);

            String Fromdate="From : "+fromDate+"         To : "+toDate+"         "+paradate;
            Paragraph parafromdate=new Paragraph(Fromdate,FontFactory.getFont(FontFactory.TIMES_BOLDITALIC,14,Font.BOLD,BaseColor.WHITE));          
            parafromdate.setAlignment(Element.ALIGN_CENTER);

            ColumnText columnfromdate=new ColumnText(canvas);
            columnfromdate.setSimpleColumn(fromdate);
            columnfromdate.addElement(parafromdate);
            columnfromdate.go();

            Rectangle bartitle=new Rectangle(570,620,374,650);//left,bottom,right,top
            bartitle.setBorder(Rectangle.BOX);
            bartitle.setBackgroundColor(new BaseColor(31,155,118));
            bartitle.setBorderWidth(2);
            bartitle.setBorderColor(new BaseColor(31,155,118));
            canvas.rectangle(bartitle);

            String BarChartTitle="                Sales Report";
            Paragraph paraBar=new Paragraph(BarChartTitle,FontFactory.getFont(FontFactory.TIMES_BOLDITALIC,14,Font.BOLD,BaseColor.WHITE));          
            paraBar.setAlignment(Element.ALIGN_CENTER);
            ColumnText columnDate=new ColumnText(writer.getDirectContent());
            columnDate.setSimpleColumn(bartitle);
            columnDate.setText(paraBar);
            columnDate.go();

            int width=450;
            int height=400;

            File Barchart=new File("BarChart.png");
            ChartUtilities.saveChartAsPNG(Barchart, barchart, width, height);

            String imageBar="BarChart.png";
            Image imgbar=Image.getInstance(imageBar);
            imgbar.scaleToFit(400, 200);
            imgbar.setAbsolutePosition(80, 430);
            canvas.addImage(imgbar);

            document.close();
            res.close();
            PStat.close();

            JOptionPane.showMessageDialog(null, "Report Generated");
        }
        catch(Exception e)
        {
            JOptionPane.showMessageDialog(null, e);
        }
    }

    /**
     * Initialize the contents of the frame.
     */
    private void initialize() {
        try
        {
            UIManager.setLookAndFeel(new WebLookAndFeel());
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
        frmSalesReport = new JFrame();
        frmSalesReport.setTitle("Sales Report");
        frmSalesReport.setBounds(100, 100, 450, 358);
        frmSalesReport.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frmSalesReport.getContentPane().setLayout(null);

        JPanel panel = new JPanel();
        panel.setLayout(null);
        panel.setBorder(new LineBorder(new Color(0, 0, 0), 1, true));
        panel.setBackground(new Color(0, 116, 90));
        panel.setBounds(10, 11, 414, 49);
        frmSalesReport.getContentPane().add(panel);

        JLabel lblSalesReport = new JLabel("Sales Report");
        lblSalesReport.setHorizontalAlignment(SwingConstants.CENTER);
        lblSalesReport.setForeground(Color.WHITE);
        lblSalesReport.setFont(new Font("Tahoma", Font.BOLD, 15));
        lblSalesReport.setBounds(10, 15, 394, 20);
        panel.add(lblSalesReport);

        JPanel panel_1 = new JPanel();
        panel_1.setBorder(new TitledBorder(null, "Search By Invoice Date", TitledBorder.LEADING, TitledBorder.TOP, null, Color.BLACK));
        panel_1.setBounds(10, 71, 414, 156);
        frmSalesReport.getContentPane().add(panel_1);
        panel_1.setLayout(null);

        JLabel lblNewLabel = new JLabel("From :");
        lblNewLabel.setBounds(10, 31, 46, 14);
        panel_1.add(lblNewLabel);

        FromDate = new JDateChooser();
        FromDate.setBounds(10, 56, 161, 25);
        panel_1.add(FromDate);

        JLabel lblTo = new JLabel("To :");
        lblTo.setBounds(243, 31, 46, 14);
        panel_1.add(lblTo);

        ToDate = new JDateChooser();
        ToDate.setBounds(243, 56, 161, 25);
        panel_1.add(ToDate);

        JButton ViewReport1 = new JButton("View Report 1");
        ViewReport1.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                GenerateReport();
            }
        });
        ViewReport1.setIcon(new ImageIcon("C:\\Users\\Mdazaz\\workspace\\InventorySystem\\Images\\Bullish_48px.png"));
        ViewReport1.setBounds(30, 105, 126, 32);
        panel_1.add(ViewReport1);

        JButton ViewReport2 = new JButton("View Report 2");
        ViewReport2.setIcon(new ImageIcon("C:\\Users\\Mdazaz\\workspace\\InventorySystem\\Images\\Pie Chart_40px.png"));
        ViewReport2.setBounds(259, 105, 126, 32);
        panel_1.add(ViewReport2);

        JPanel panel_2 = new JPanel();
        panel_2.setBorder(new LineBorder(new Color(0, 0, 0), 1, true));
        panel_2.setBounds(10, 232, 414, 70);
        frmSalesReport.getContentPane().add(panel_2);
        panel_2.setLayout(null);

        JButton Reset = new JButton("Reset");
        Reset.setIcon(new ImageIcon("C:\\Users\\Mdazaz\\workspace\\InventorySystem\\Images\\Refresh_40px.png"));
        Reset.setBounds(62, 18, 126, 32);
        panel_2.add(Reset);

        JButton Close = new JButton("Close");
        Close.setIcon(new ImageIcon("C:\\Users\\Mdazaz\\workspace\\InventorySystem\\Images\\Close Window_48px.png"));
        Close.setBounds(238, 18, 126, 32);
        panel_2.add(Close);
    }
}

代替问号的是什么?这个问题的一般版本是:如何在单击元素的正下方选择一个非子缩进元素?

我最好的尝试是:

<ul id="thing_list">
        <li><div class="thing"><span>Thing 1</span></div></li>
            <div class="properties">
                <ol class="settings">
                    <li><span>Setting 1</span></li>
                        <div class="setting_explain">
                            <p class="explanation"><span>Explanation 1</span></p>
                        </div>
                    <li><span>Setting 2</span></li>
                        <div class="setting_explain">
                            <p class="explanation"><span>Explanation 2</span></p>
                        </div>

这显然不起作用,因为它总是只切换列表中的第一个p.explanation,而不是直接位于list元素本身下面的第一个p.explanation。

3 个答案:

答案 0 :(得分:1)

试试这个

$('ol.settings li').click(function(e) {
    $(this).siblings('.setting_explain').find('p.explanation').toggle();
  });

答案 1 :(得分:1)

您的HTML标记无效,div.setting_explain应位于li下。请检查以下代码段。

$('ol.settings li').click(function(e) {
  $(this).find('p.explanation').toggle();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul id="thing_list">
  <li>
    <div class="thing"><span>Thing 1</span></div>
    <div class="properties">
      <ol class="settings">
        <li><span>Setting 1</span>
          <div class="setting_explain">
            <p class="explanation"><span>Explanation</span></p>
          </div>
        </li>

        <li><span>Setting 2</span>
        <div class="setting_explain">
            <p class="explanation"><span>Explanation</span></p>
          </div>
        </li>
      </ol>
    </div>
  </li>
</ul>

答案 2 :(得分:0)

你为什么选择父母?

$('ol.settings li').click(function(e) {
  $(this).children('.explanation').toggle();
});