javascript - 我的行没有变成按钮,而是消失了
问题描述
我有下一个问题:只要输入字段被检查并正确填写,它们应该变成绿色按钮,但是每当检查发生并且它们应该变成绿色按钮时,它们就会消失。我console.log()
是绿色按钮,它返回“未定义”给我。查看图片,然后是前 3 个输入字段:
如您所见,它们消失了。我确实检查了元素,但找不到它们。
我的代码如何:
$.map(exercise.syllables, function (syllable, j) {
if (!syllable || !syllable.trim().length) {
// If it doesn't exist or is an empty string, return early without creating/appending elements
return;
}
var innerSylCol = $('<div/>', {
class: 'col-md-3 inputSyllables'
});
var sylInput = $('<input/>', {
'type': 'text',
'class': 'form-control syl-input',
'name': +c++,
'id': +idsyll++
}).on('blur', function() {
var cValue = $(this).val();
if(cValue === "") {
return;
}
if (cValue === syllable) {
correctSylls.push(cValue);
console.log(correctSylls);
}
if (exercise.syllables.length === correctSylls.length) {
$(this).closest('.syll-row').find('input.syl-input').replaceWith(getCorrectBtn(cValue));
// console.log(getCorrectBtn(cValue));
S.addRight();
S.playRight();
} else if (cValue !== syllable){
$(this).css({'color':'#e00413'});
S.playWrong();
S.addWrong();
}
});
我创建按钮的功能:
function getCorrectBtn(value) {
var correctBtn = $('<button/>', {
'class': 'btn btn-success buttonCorrect',
'type': 'button',
'id': "button" + CBC++,
'value': value
});
}
以及可能与我的输入字段相关的所有 CSS:
input[type="text"] {
font-size: 150%;
margin-top: 1vh;
transition: color 1s;
}
.btn {
margin: 0;
display: inline-block;
height: 38px;
margin: 5px;
outline: none !important;
}
input {
width:100%;
padding:5px;
outline: none !important;
text-align: center;
}
解决方案
推荐阅读
- android - 如何更改 OSM 地图自定义主题?
- hugo - Hugo – 在不同环境下使用不同的主题
- python - PixbufAnimation.get_iter 需要弃用的 GLib.TimeVal
- python-3.x - 解释 sklearn 随机森林的详细输出
- ios - 不能在 NMACoreRouter 上使用循环(swift)(HereMap SDK)
- javascript - 无法连接到 websocket
- reactjs - 缩小 TailwindCSS buid、PostCSS 的结果
- esp8266 - 为什么我在刷 esp8266 时收到 --flash_freq" 必须是一个数字(ESPTOOL-256)?
- tableau-api - 如何计算画面中的连续状态?
- php - 如何在 xampp 中启用虚拟主机