M_V*_*M_V -2 javascript syntax function
我不明白为什么只有stFunction()作品?为什么我得到语法错误(意外的标记".")ndFunction()和错误rdFunction()?谢谢你的帮助
function stFunction() {
var x = document.getElementById("id1");
x.value = x.value.toUpperCase();
}
function ndFunction() {
var y.value = document.getElementById("id2").value.toUpperCase();
}
function rdFunction() {
var y = {};
y.value = document.getElementById("id3").value.toUpperCase();
}
Run Code Online (Sandbox Code Playgroud)
您的ndFunction无法正常工作,因为当您尝试设置它的属性时y不存在.至于rdFunction,只要你的元素存在并且有一个值,它应该可以正常工作.
function ndFunction() {
var y = {},
y.value = document.getElementById("id2").value.toUpperCase();
}
Run Code Online (Sandbox Code Playgroud)