开发者

Can you update a label with javascript?

I ha开发者_运维知识库ve a javascript function that I am trying to get to update a label. If I replace the label with a textbox it works fine, but with the label nothing happens!

An example of a label:

<label id="163" name="163">Some text.</label>

javascript code:

$("#163").val("meep");


The val method sets the value of an input element. It will have no effect on other elements, including <label>

You need to call the text method, which sets the text of any element.

For example:

$("#163").text("meep");


The <label> element is not an input control, and it has no concept of a "value". It sounds like you are simply trying to change the text on the label. This can be achieved using the text(str) method:

$("#163").text("meep");


Try text method :

$("#163").text("meep");


Also, ID and NAME attributes should not start with a number, though most times this will not actually cause a problem.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜