我有一段关于点击事件的代码,用于设置 session 变量。控制台登录在事件点击中工作,但它不会进入 if 条件:
'click .family': function(event) {
event.preventDefault();
console.log('in change'); // result in change
$("#btnFamily").html(event.target.text);
var role = event.target.text;
console.log('role',role); //result role Fils
if(role == "Fils"){
console.log('here in son'); //never comes here
Session.set('family', "Son"); //never comes here
}
},
最佳答案
如果您使用 Javascript,则使用 role.trim()=='Fils';如果使用 jQuery,则使用 $.trim(role)=='Fils'
您可以使用三重等于(===)运算符进行严格验证
我认为这会有所帮助..
关于javascript - 如果在 javascript-meteor 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43107793/