首页 > 解决方案 > 我想在单击按钮时隐藏文本框

问题描述

我想在单击按钮时隐藏文本框,问题是按钮已经隐藏,更改该文本框中的文本后将显示该按钮

标签: javascripthtmlcss

解决方案


我认为这可能对您有用,但是就像其他人说的那样,如果您不发布代码很难回答:P

document.querySelector('#yourinput > location > etc').onkeypress = function() {
    //If our text input detects a key press do this function
    /*
    //Optional*
    if (document.querySelector('#yourinput > location > etc').value == "MagikWord"){
    document.querySelector('#yourbutton').style.display = "block";
    }
    else{
    document.querySelector('#yourbutton').style.display = "none";
    }
    //With this additional condition your button wont show up until you type "MagikWord"
    */
    document.querySelector('#yourbutton').style.display = "block";
}
document.querySelector('#yourbutton').onclick = function(){
    document.querySelector('#yourinput > location > etc').style.display = "none";
}

推荐阅读