I have been making a simple program and when I run the function "convert()" it does not do anything. It is definitely a problem with the var data line because I have tried using // to make it a comment and it works. Please help me have this work. Here is my javascript code for convert():
function convert(){
var data = document.getElementById("inputArea").split(":");
for(var i=0; i<data.length; i++) { data[i] = +data[i]; }
document.write("It works!");
}
You need to take the value of the input element and not the input itself.
the right code :
function convert(){
var data = document.getElementById("inputArea").value.split(":");
for(var i=0; i<data.length; i++) { data[i] = +data[i]; }
document.write("It works!");
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.