开发者

Javascript needed for finding a box in a html page then setting contents

Can anyone show me how to get to a text edit box in a html page and set its value 开发者_运维百科using Java script please?


Given a text box

<input type="text" id="MyInput">

You Javascript would look like:

document.getElementById("MyInput").value = "some value";

There will be other ways of doing this if you are using a JavaScript framework, for example in jquery, the following will suffice:

$("#MyInput").val("some value");


<input type="text" id="ExampleTextBox" />

If you know the id of it:

document.getElementById(TEXTBOX_ID).value = YOUR_VALUE;

or in a function:

function chanageTextBoxValue(newValue)
{
   document.getElementById('ExampleTextBox').value = newValue;
}


You can access it through your form:

document.myForm.firstName.value = "Hello World";

--

<form name="myForm">
  <input type="text" name="firstName" />
</form>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜