Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/376.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何更改HTML文件';通过Javascript文件创建字段_Javascript_Html - Fatal编程技术网

如何更改HTML文件';通过Javascript文件创建字段

如何更改HTML文件';通过Javascript文件创建字段,javascript,html,Javascript,Html,大家好,我在一个项目中,我想更改html字段的值,如textarea复选框等 我的javascript文件变量上有一些值,如何将变量的值分配给外部html文件的字段 任何帮助都应该被感激,这将是对我的巨大帮助 var profiledata; var ushurCallbackGetProfile = function (response) { profiledata = response; alert(profiledata); // in the above "profiledata

大家好,我在一个项目中,我想更改html字段的值,如textarea复选框等

我的javascript文件变量上有一些值,如何将变量的值分配给外部html文件的字段

任何帮助都应该被感激,这将是对我的巨大帮助

var profiledata;
var ushurCallbackGetProfile = function (response) {

profiledata = response;


alert(profiledata);

// in the above "profiledata" i get some value like "HAI"..


};
我想将这个“HAI”值分配给一个html文件的文本区域

HTML文件的格式如下所示

enter code here <html><form id="userFormchange" method="post"><label style="margin-left:513px;">Display Name</label><input name="profileusername" type="text" placeholder="Your Nickname" id="nickname" style="margin-left: 82px;"></form></html>
在此处输入代码显示名称
我想为上面的输入名称“profileusername”分配“HAI”值

我该怎么做?

例如,
document.getElementById(id).attribute=新值


这应该会有所帮助。我相信这回答了你的问题,但如果没有,我可以尝试进一步帮助你。

你可以这样做

document.getElementById(textareaid).innerHTML = value;


选择文本字段并设置
innerHTML
属性:

HTML

JS小提琴示例


如果要更改元素中的文本,则必须使用

document.getElementById(id).innerHTML = "New text!";

非常感谢兄弟。。。你救了我一天。。工作完美。。。你真可怕。。。。
<textarea class="content"></textarea>
var textarea = document.querySelector('.content');
var profiledata;

var ushurCallbackGetProfile = function (response) {
    profiledata = response;
    textarea.value = profiledata;
};

ushurCallbackGetProfile('some content');
document.getElementById(id).innerHTML = "New text!";