我习惯于编写jQuery,所以我认为这应该很简单,但是我一直遇到未定义的错误。
在Javascript中,我只想检查用户是否输入了正确的代码,如果输入正确,则显示隐藏的div。我有switch语句switch,但是我无法设置正确的参数来显示div。
先谢谢您!
cy.get('table').contains('td', 'jacobs').should('be.visible');
cy.get('table').contains('td', 'jacobs').then(elem => {
// Do something with this specific element...
});
// etc...
function codeValidation() {
// the response which varies
var text;
// the input which has one true value
var specialCode = document.getElementById("myInput").value;
// the case
switch (specialCode) {
case "COLA2018":
// Show the hidden ID
break;
default:
text = "Please enter a valid code.";
}
document.getElementById("codeErrorMSG").innerHTML = text;
}
input#myInput[type=text] {
padding: 12px 20px;
margin: 8px 0;
display: inline-block;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
}
div#codeErrorMSG {
display: none;
font-weight: bold;
color: red;
}