用Javascript更改标签

时间:2015-07-12 16:31:51

标签: javascript

我找到了答案但却找不到任何答案。我正在尝试更改标签中的文字,但没有成功

HTML

<li id="123" class="xxx">
  <label class="xxx" for="xxx">Something</label>
</li>

当前Javascript

<script>
documentquerySelector("li#field_2_31 label").innerHTML = 'New label';
</script>

3 个答案:

答案 0 :(得分:3)

您需要介于documentquerySelector之间的句点:

document.querySelector("#field_2_31 label").innerHTML = 'New label';

答案 1 :(得分:0)

这可能与您为此帖子编辑示例的方式存在差异,但您选择li且标识为field_2_31li的标识为123

答案 2 :(得分:0)

HTML:

import java.awt.GridLayout;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;

public class PictureTester extends JFrame{

    private static final long serialVersionUID = 1L;

    public static void main(String[] args) {
        new PictureTester().setVisible(true);
    }

    public PictureTester(){
        super();
        setSize(600, 600);
        setLayout(new GridLayout());
        java.net.URL imgUrl = PictureTester.class.getResource("C:\\Users\\Harry\\Desktop\\LearnJava\\pug-image3.jpg");
        ImageIcon image = new ImageIcon(imgUrl);    
        JLabel display = new JLabel(image);

        add (display);
    }
}

JS:

<li id="field_2_31" class="xxx">
  <label class="xxx" for="xxx">Something</label>
</li>

请参阅Fiddle以了解示例。