javascript - 从函数jquery中的函数获取值
问题描述
我真的很想从这个函数中获取一个值,我的猜测是这是因为函数内部的函数。
(ps。我知道当我想获得一个 BOOL 值时我不必使用引号)
请帮忙
$(document).ready(function() {
var text = null;
function textCheck() {
if ($('.window-' + sc).has('input[type="text"]')) {
$(this).find('input[type="text"]').each(function() {
$(this).on('click', function() {
if ($(this).attr('required')) {
var placeholder = $(this).attr('original');
if (!$(this).val() == '') {
$(this).removeClass('is-invalid shake').addClass('is-valid').attr('placeholder', placeholder);
text = 'true';
//return text;
} else {
$(this).addClass('is-invalid shake').attr('placeholder', placeholder + " can't be empty");
text = 'false';
//return text;
};
};
});
});
};
return text;
};
var texxt = textCheck();
console.log(texxt);
});
解决方案
在您的 textCheck() 函数中,第一个 $(this) 代表窗口
将其更改为您的元素
推荐阅读
- android - 如何获取 FloatingActionButton 的当前颜色
- python - Heroku 减少 TensorFlow 应用程序的内存消耗
- javascript - 类型错误:无法读取 undefined-Discord.js 的属性“内容”
- esp8266 - esp8266 - 如何在 spi 上写入代码段?
- python - 如何绘制不同颜色的线
- python - 2 一次变换的数据帧乘法
- angular - 使用 rxjs 在 Angular 中转换 http 服务响应
- php - 如何让 Oracle 在查询中保留标识符的大小写?
- javascript - 如何设置在材质ui文本字段中弹出建议的方式
- typescript - 为什么 TypeORM 需要第二个参数 inverseSide 属性(即使它是可选的)