javascript:当另一个输入值更改时,如何清理输入框?
我在另一个输入(#家长)的基础上进行了一个输入(#孩子)自动建议。当#父输入值更改时,我想清除#子输入值。我想学习如何做到这一点,谢谢 您可以订阅父对象的javascript:当另一个输入值更改时,如何清理输入框?,javascript,Javascript,我在另一个输入(#家长)的基础上进行了一个输入(#孩子)自动建议。当#父输入值更改时,我想清除#子输入值。我想学习如何做到这一点,谢谢 您可以订阅父对象的onchange事件,然后清除子对象的值: window.onload = function() { // the document has loaded => we could access the DOM // we subscribe to the onchange event pf the parent:
onchange
事件,然后清除子对象的值:
window.onload = function() {
// the document has loaded => we could access the DOM
// we subscribe to the onchange event pf the parent:
document.getElementById('parentId').onchange = function() {
// and when this event is triggered we clean the child
// element value
document.getElementById('childId').value = '';
};
};