显示/隐藏onClick JQuery
我想显示/隐藏显示/隐藏onClick JQuery,jquery,css,Jquery,Css,我想显示/隐藏display:none的文本。现在,一旦文本已经显示,它仍然会显示。谢谢你的帮助 $(“#提交”)。单击(函数(e){ e、 预防默认值(); str=$('#string').val(); if(checkPalin(str)){ 返回$('#true').css('display','block'); }否则{ 返回$('#false').css('display','block'); } }); #结果跨度{ 显示:无; 字体大小:粗体; } 这根绳子是一根绳子! 这
display:none的文本单击按钮并清除onClick函数上的输入字段后,CSS上的code>。现在,一旦文本已经显示,它仍然会显示。谢谢你的帮助
$(“#提交”)。单击(函数(e){
e、 预防默认值();
str=$('#string').val();
if(checkPalin(str)){
返回$('#true').css('display','block');
}否则{
返回$('#false').css('display','block');
}
});代码>
#结果跨度{
显示:无;
字体大小:粗体;
}
这根绳子是一根绳子!
这个字符串是
不是罗马
试试:
基本上,您将按原样检查条件,除非您将使用Hide()和Show()方法根据需要显示结果。“单击按钮后”什么按钮?您好@kritiya Clark,您的问题不清楚它只在第一次单击时起作用,文本仍会显示,而不会从DOM中删除。两个文本并排显示。
$('#submit').click(function (e) {
e.preventDefault();
str = $('#testString').val();
// Console logging
console.log('The value entered was: ' + str);
if (checkPalin(str)) {
// Clear the value of #testString
$('#testString').val('');
// Display the #true result
$('#true').show();
// Hide the #false result
$('#false').hide();
// Console logging
console.log('The value ' + str + ' passed our condition');
} else {
// Clear the value of #testString
$('#testString').val('');
// Display the #false result
$('#false').show();
// Hide the #true result
$('#true').hide();
// Console logging
console.log('The value ' + str + ' failed our condition');
}
return false;
});