使用jquery,我试图复制每个"价格"每个"标题"之后的div格。
public CreatePanel(JFrame frame) {
ext = new ArrayList<>();
files = new ArrayList<>();
this.mainWindow = frame;
this.setSize(256, 256);
cards = new CardLayout();
this.setLayout(cards);
panel1 = new JPanel(null);
createPanel1(panel1);
this.add(panel1, "panel1");
panel2 = new JPanel(null);
createPanel2(panel2);
this.add(panel2, "panel2");
panel3 = new JPanel(null);
createPanel3(panel3);
this.add(panel3, "pp");
cards.show(this, "panel1");
}
public class ProgressPanel {
private static JPanel panel;
private static JProgressBar progressBar;
private static int progress;
public static JPanel createProgressPanel(){
ProgressPanel.panel = new JPanel(null);
ProgressPanel.initPanel();
return ProgressPanel.panel;
}
private static void initPanel(){
panel.setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
progressBar = new JProgressBar(0, 100);
progressBar.setValue(progress);
progressBar.setStringPainted(true);
panel.add(progressBar, c);
}
public static void updateProgress(int x){
ProgressPanel.progress += x;
}
public void resetProgress(){
this.progress = 0;
}
}
所以它看起来像这样:
<table>
<tr>
<td><div class="title">Item Title 1</div></td>
<td><div class="price">$99.99</div></td>
<tr>
<tr>
<td><div class="title">Item Title 2</div></td>
<td><div class="price">$89.99</div></td>
<tr>
<tr>
<td><div class="title">Item Title 3</div></td>
<td><div class="price">$79.99</div></td>
<tr>
</table>
我尝试过使用jquery脚本:
<table>
<tr>
<td><div class="title">Item Title 1</div><div class="price">$99.99</div></td>
<td><div class="price">$99.99</div></td>
<tr>
<tr>
<td><div class="title">Item Title 2</div><div class="price">$89.99</div></td>
<td><div class="price">$89.99</div></td>
<tr>
<tr>
<td><div class="title">Item Title 3</div><div class="price">$79.99</div></td>
<td><div class="price">$79.99</div></td>
<tr>
</table>
这不起作用 - 它只需要每个价格并将其附加到每个标题上(换句话说,每个标题最终会有3个价格)。
有没有人有任何想法?
答案 0 :(得分:0)
$(newLink).insertAfter('.title');
.title会找到该类的所有元素。要获得与您的价格相关的信息,您可以
$(newLink).insertAfter( $(this).closest('tr').find('.title') );