小编jav*_*guy的帖子

setAttribute在JavaScript中不起作用

我正在使用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)

为什么这不能按我预期的那样工作,我该如何解决?

html javascript

2
推荐指数
1
解决办法
2514
查看次数

标签 统计

html ×1

javascript ×1