[英]How to use update button to change the text of an input field using a JavaScript function?
I am doing an assignment to update a text field when an update button is pressed so far. 到目前为止,当我按下更新按钮时,我正在分配一个文本字段。 My code looks like this:
我的代码如下所示:
function updatePhotoInfo(){
var retrieve_images_script = SERVER + "/image.php?username="+USERNAME;
//@ToDo
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (xhttp.readyState == 4 && xhttp.status == 200) {
imageData= JSON.parse(xhttp.responseText);
console.log(imageData.length);
}
};
xhttp.open("GET", retrieve_images_script, false);
xhttp.send();
var dField = document.getElementsByClassName("dField").innerHTML;
var updateField = document.getElementsByClassName("dField").new.innerHTML;
console.log("dField");
if (dField != updateField) {
dField == updateField;
};
So generally what I would do is the following. 因此,通常我会做以下事情。 Say we have a button with ID=my-btn
假设我们有一个ID = my-btn的按钮
document.getElementsByID('my-btn').onclick = function(){
//If the name of your text filed ID is my-txt
document.getElementsByID('my-txt').innerHTML = "DONE!"
}
This is one way to do it, but if you have the option take a looking into jquery. 这是一种实现方法,但是如果您有选择的话,可以看看jquery。 It makes this kind of stuff a lot easier to manage.
它使这种东西易于管理。
See this Pen for details CODE PEN 有关详细信息,请参见此笔
EDIT: This one includes a field: SAME WITH Field 编辑:这包括一个字段: 与字段相同
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.