Javascript 在Ember.js应用程序中实现jQuery
我曾要求为一个在Ember.js中创建的应用程序制作tweeks,但我没有太多的经验。我已经删除/添加了字段,添加了必要的文本,最后一项任务是验证字段(电话号码),以确保它们完全相同。它在我的本地主机上工作,但在Ember应用程序上不工作 这里是Ember.jsJavascript 在Ember.js应用程序中实现jQuery,javascript,jquery,ember.js,Javascript,Jquery,Ember.js,我曾要求为一个在Ember.js中创建的应用程序制作tweeks,但我没有太多的经验。我已经删除/添加了字段,添加了必要的文本,最后一项任务是验证字段(电话号码),以确保它们完全相同。它在我的本地主机上工作,但在Ember应用程序上不工作 这里是Ember.js data.buffer.push("\n </div>\n </div>\n\n <div class=\"form- row\">\n <div class=
data.buffer.push("\n </div>\n </div>\n\n <div class=\"form-
row\">\n <div class=\"field w100\">\n <label for=\"primary_phone\">Primary phone (digits only) *</label>\n ");
hashContexts = {'type': depth0,'name': depth0,'required': depth0,'placeholder': depth0,'title': depth0};
hashTypes = {'type': "STRING",'name': "STRING",'required': "STRING",'placeholder': "STRING",'title': "STRING"};
options = {hash:{
'type': ("number"),
'name': ("primary_phone"),
'required': ("required"),
'placeholder': ("e.g. 12025556789 (country code + area code + local number without dashes)"),
'title': ("e.g. 12025556789 (country code + area code + local number without dashes)")
},contexts:[],types:[],hashContexts:hashContexts,hashTypes:hashTypes,data:data};
data.buffer.push(escapeExpression(((stack1 = helpers.input || depth0.input),stack1 ? stack1.call(depth0, options) : helperMissing.call(depth0, "input", options))));
data.buffer.push("\n </div>\n </div>\n\n <div class=\"form-row\">\n <div class=\"field w100\">\n <label for=\"confirm_phone\">Confirm Primary phone (digits only) *</label>\n ");
hashContexts = {'type': depth0,'name': depth0,'required': depth0,'placeholder': depth0,'title': depth0};
hashTypes = {'type': "STRING",'name': "STRING",'required': "STRING",'placeholder': "STRING",'title': "STRING"};
options = {hash:{
'type': ("number"),
'name': ("confirm_phone"),
'required': ("required"),
'placeholder': ("e.g. 12025556789 (country code + area code + local number without dashes)"),
'title': ("e.g. 12025556789 (country code + area code + local number without dashes)")
},contexts:[],types:[],hashContexts:hashContexts,hashTypes:hashTypes,data:data};
data.buffer.push(escapeExpression(((stack1 = helpers.input || depth0.input),stack1 ? stack1.call(depth0, options) : helperMissing.call(depth0, "input", options))));
data.buffer.push(“\n\n\n\n\n主电话(仅数字)*\n”);
HashContext={'type':depth0,'name':depth0,'required':depth0,'placeholder':depth0,'title':depth0};
hashTypes={'type':“STRING”、'name':“STRING”、'required':“STRING”、'placeholder':“STRING”、'title':“STRING”};
选项={hash:{
“类型”:(“编号”),
“姓名”:(“主要电话”),
“必需”:(“必需”),
“占位符”:(“例如12025556789(国家代码+区号+不带破折号的本地号码)”,
“标题”:(“例如12025556789(国家代码+区号+不带破折号的本地号码)”)
},context:[],type:[],hashcontext:hashcontext,hashTypes:hashTypes,data:data};
data.buffer.push(escapeeexpression((stack1=helpers.input | | depth0.input),stack1?stack1.call(depth0,options):helperMissing.call(depth0,“input”,options));
data.buffer.push(“\n\n\n\n\n\n确认主电话(仅数字)*\n”);
HashContext={'type':depth0,'name':depth0,'required':depth0,'placeholder':depth0,'title':depth0};
hashTypes={'type':“STRING”、'name':“STRING”、'required':“STRING”、'placeholder':“STRING”、'title':“STRING”};
选项={hash:{
“类型”:(“编号”),
“姓名”:(“确认电话”),
“必需”:(“必需”),
“占位符”:(“例如12025556789(国家代码+区号+不带破折号的本地号码)”,
“标题”:(“例如12025556789(国家代码+区号+不带破折号的本地号码)”)
},context:[],type:[],hashcontext:hashcontext,hashTypes:hashTypes,data:data};
data.buffer.push(escapeeexpression((stack1=helpers.input | | depth0.input),stack1?stack1.call(depth0,options):helperMissing.call(depth0,“input”,options));
这是我的jQuery
$(function(){
var $primaryNo = $("input[name='primary_phone']");
var $confirmNo = $("input[name='confirm_phone']");
var $btn = $('#button');
$primaryNo.keypress(function(key) {
if(key.charCode < 48 || key.charCode > 57)
return false;
});
$confirmNo.keypress(function(key) {
if(key.charCode < 48 || key.charCode > 57)
return false;
});
$btn.click(function() {
if ($primaryNo.val() !== $confirmNo.val()) {
alert('The numbers from the Primary Phone field and the Confirm Primary Phone field do not match. Please re-enter');
} else {
return true;
}
});
});
$(函数(){
var$primaryNo=$(“输入[name='primary\u phone']);
var$confirmNo=$(“输入[name='confirm\u phone']);
变量$btn=$(“#按钮”);
$primaryNo.keypress(功能(键){
如果(key.charCode<48 | | key.charCode>57)
返回false;
});
$confirmNo.keypress(功能(键){
如果(key.charCode<48 | | key.charCode>57)
返回false;
});
$btn.单击(函数(){
如果($primaryNo.val()!=$confirmNo.val()){
警报(“主电话字段和确认主电话字段中的号码不匹配。请重新输入”);
}否则{
返回true;
}
});
});
我已经使用console.log进行了一些测试,Ember应用程序正在获取我包含的.js文件,但是当我在字段中插入两个不同的数字时,单击submit时,它不会提醒用户它们不正确
有什么想法吗 尝试事件委派:
$(function(){
var $primaryNo = $("input[name='primary_phone']");
var $confirmNo = $("input[name='confirm_phone']");
var $btn = $('#button');
$('body').on('keypress',$primaryNo,function(key) {
if(key.keyCode < 48 || key.keyCode > 57)
return false;
});
$('body').on('keypress',$confirmNo,function(key) {
if(key.keyCode < 48 || key.keyCode > 57)
return false;
});
$('body').on('click',$btn,function(e) {
e.preventDefault();
if ($primaryNo.val() !== $confirmNo.val()) {
alert('The numbers from the Primary Phone field and the Confirm Primary Phone field do not match. Please re-enter');
} else {
$(this).closest('form').submit();
}
});
});
$(函数(){
var$primaryNo=$(“输入[name='primary\u phone']);
var$confirmNo=$(“输入[name='confirm\u phone']);
变量$btn=$(“#按钮”);
$('body')。在('keypress',$primaryNo,函数(键){
如果(key.keyCode<48 | | key.keyCode>57)
返回false;
});
$('body')。在('keypress',$confirmNo,function(key){
如果(key.keyCode<48 | | key.keyCode>57)
返回false;
});
$('body')。在('click')上,$btn,函数(e){
e、 预防默认值();
如果($primaryNo.val()!=$confirmNo.val()){
警报(“主电话字段和确认主电话字段中的号码不匹配。请重新输入”);
}否则{
$(this).closest('form').submit();
}
});
});
尝试事件委派:
$(function(){
var $primaryNo = $("input[name='primary_phone']");
var $confirmNo = $("input[name='confirm_phone']");
var $btn = $('#button');
$('body').on('keypress',$primaryNo,function(key) {
if(key.keyCode < 48 || key.keyCode > 57)
return false;
});
$('body').on('keypress',$confirmNo,function(key) {
if(key.keyCode < 48 || key.keyCode > 57)
return false;
});
$('body').on('click',$btn,function(e) {
e.preventDefault();
if ($primaryNo.val() !== $confirmNo.val()) {
alert('The numbers from the Primary Phone field and the Confirm Primary Phone field do not match. Please re-enter');
} else {
$(this).closest('form').submit();
}
});
});
$(函数(){
var$primaryNo=$(“输入[name='primary\u phone']);
var$confirmNo=$(“输入[name='confirm\u phone']);
变量$btn=$(“#按钮”);
$('body')。在('keypress',$primaryNo,函数(键){
如果(key.keyCode<48 | | key.keyCode>57)
返回false;
});
$('body')。在('keypress',$confirmNo,function(key){
如果(key.keyCode<48 | | key.keyCode>57)
返回false;
});
$('body')。在('click')上,$btn,函数(e){
e、 预防默认值();
如果($primaryNo.val()!=$confirmNo.val()){
警报(“主电话字段和确认主电话字段中的号码不匹配。请重新输入”);
}否则{
$(this).closest('form').submit();
}
});
});
您发布的代码与Ember.js代码不同。之前的开发人员说他使用了Ember.js。你认为它是用什么写的?HTML5产生的显示:可能是一个非常旧的版本或构建工件?看看,并得到一个感觉如何余烬应用程序应该看起来像这些天。也许有一个package.json或bower.json让您了解依赖关系?我来看看。谢谢你所发布的代码看起来不像Ember.js。之前的开发人员说他使用了Ember.js。你认为它是用什么写的?HTML5产生的显示:可能是一个非常旧的版本或构建工件?看看,并得到一个感觉如何余烬应用程序应该看起来像这些天。也许有一个package.json或bower.json让您了解依赖关系?我来看看。谢谢谢谢谢谢,但还是不走运,而且我还有其他需要文本输入的字段控制台中有哪些错误?你的代码会触发吗?如果它是一个Ember.js应用程序,你不应该使用jQuery,至少不应该这样。对于验证,您将使用验证状态/错误消息。有。所以让我们先弄清楚这一点。它不会出现任何错误。它正在读取文件并记录我发出的任何命令,但它似乎没有验证这两个字段您的按键事件触发了吗?谢谢,但仍然没有运气,而且我还有其他需要文本输入的字段控制台中有哪些错误?你的代码触发了吗?如果它是一个Ember.js ap