开发者

How do you change the value of an HTML element with javascript?

I have this: <input type="button" value="hello"> I want to change the va开发者_JAVA百科lue with javascript so that it is value="goodbye". How do I do this?

Following @David's advice in the comments below here is the code I tried but could not get to work before posting this question:

var createBttn = document.getElementById('create');
createBttn.innerHTML = 'value="goodbye"';


First you need to get a reference to the object that you want to change the value on, then assign the value property of that element, like this:

Say your element had an id of "someButton":

var btn = document.getElementById('someButton');
btn.value = 'goodbye';
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜