Home  >  Article  >  Web Front-end  >  How to set value in javascript

How to set value in javascript

醉折花枝作酒筹
醉折花枝作酒筹Original
2021-04-16 15:55:003392browse

JS method of setting value: 1. Use innerHTML attribute, syntax "document.getElementById('id name').innerHTML=value"; 2. Use val() function, syntax "$(selector). val(value)".

How to set value in javascript

The operating environment of this tutorial: Windows 7 system, JavaScript version 1.8.5, Dell G3 computer.

First type:

html document code is as follows:

<td style="border:1px solid #c0c0c0;" id="name"></td>

js value method:

document.getElementById(&#39;name&#39;).innerHTML = data.name;

Second type

html The document code is as follows:

<td><input type="text" id="name" class="easyui-validatebox" style="width:150px;" data-options="required:true" /></td>

js value method:

var name = data.name;
$(&#39;#name&#39;).val(name);

[Recommended learning: javascript advanced tutorial]

The above is the detailed content of How to set value in javascript. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn