js.erb 文件中的比较运算符
我有一个名为 new.js.erb 的文件,其中包含以下行:
if( $('#user_password').val().length < 6 )
由于某种原因,小于号会破坏整个文件。我认为 Rails 正在看到 <由于某种原因,符号作为标签的开头。我只想检查 user_password 字段中的值的字符串长度是否小于 6。有没有办法在 js.erb 文件中的 jQuery 中执行此操作?
令人惊讶的是,我所有的谷歌搜索和搜索都没有找到解决方案。
如果您需要更多信息,请随时询问。
感谢您的帮助!
mu 的更多代码(我可以保证此块上方和下方的所有内容都工作正常):
if( $('#user_password').text().length < 6 )
{
$('form.edit_user').submit();
popup.unload();
$('#send_after_pass').show();
$('#send_after_pass').click(function(e) {
$(this).hide();
$('form.new').submit();
});
else
{
$('#errors').html("Password must be 6 characters or longer.");
}
编辑:我对虚假报价很不满意!假装它从未存在过...但这不是导致我的问题的原因。
I have a file called new.js.erb that contains this line:
if( $('#user_password').val().length < 6 )
For some reason, the less-than symbol breaks down the whole file. I think Rails is seeing the < symbol as the beginning of a tag for some reason. I just want to check if the value in the user_password field has a string length less than 6. Is there a way to do this in jQuery in a js.erb file?
Amazingly, all my Googling and SO searching have not uncovered a solution.
If you need any more information, please don't hesitate to ask for it.
Thank you for any help!
More code for mu (I can guarantee everything above and below this block is working fine):
if( $('#user_password').text().length < 6 )
{
$('form.edit_user').submit();
popup.unload();
$('#send_after_pass').show();
$('#send_after_pass').click(function(e) {
$(this).hide();
$('form.new').submit();
});
else
{
$('#errors').html("Password must be 6 characters or longer.");
}
EDIT: My bad on the bogus quote! Pretend it was never there... That isn't what caused my problem, though.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我在您发布的代码中没有看到任何 ERB,但缺少右大括号,您的代码应该看起来更像这样:
请注意我在
else
上方添加的右大括号。I don't see any ERB in the code you posted but there is a missing closing brace, your code should look more like this:
Note the closing brace I added above your
else
.为什么不尝试反转条件,就像这样,看看它是否确实是操作员?
Why not try to reverse the condition, like this and see if it is indeed the operator?