我正在使用setAttribue如下。它仅在第一次工作,之后显示变化的值,alert但不显示document.getElementById("to").setAttribute("value", selValue);
document.getElementById("listcontact").onchange = function () {
var selIndex = document.getElementById("listcontact").selectedIndex;
var selValue = document.getElementById("listcontact").options[selIndex].innerHTML;
var contactVal = selValue.split(';');
var phone = contactVal[2];
alert(phone);
document.getElementById("to").setAttribute("value", selValue);
selIndex = "";
selValue = "";
phone = "";
selValue = "";
};
Run Code Online (Sandbox Code Playgroud)
为什么这不能按我预期的那样工作,我该如何解决?