Tom*_*Tom 2 forms events textbox blur backbone.js
我几乎是新手的骨干.我正在向mysql提交表单数据.
我有一个特殊的输入框,其中使用他或她的电子邮件地址中的类型作为用户名.就目前而言,我可以检查所有输入字段(用户,通行证,地址,电话等)客户端,使用按钮上的事件,加载模型,使用PHP将数据放入数据库.这很好用,并经过测试.后端验证工作正常,并在必要时提供给浏览器.
现在我想在写入记录之前检查后端的loginname字段(我知道我可以在最后的提交中将其记录在后端但是想在这里进行).如果用户已经拥有一个具有相同电子邮件地址的帐户,我想抓住该客户端.问题是当我离开loginname字段时,我似乎无法找到捕获这种模糊(或onblur或改变我使用的任何东西)的方法,所以我可以(在视图的渲染中我可以想到的全部)去掉,再次使用PHP并发回"新"或"现有"标志
Google开发者工具中没有错误
define([
'jquery',
'underscore',
'backbone',
'lib/jquery-migrate-1.2.1',
'models/RegisterModel',
'text!templates/RegisterTemplate.html',
'lib/jquery.maskedinput-1.0',
'lib/bootstrap-acknowledgeinput.min',
'lib/jqBootstrapValidation'
], function($, _, Backbone, jQueryMigrate, RegisterModel, RegisterTemplate,
MaskedInput,Ack, jqAck){
var RegisterView = Backbone.View.extend({
el: $("#container"),
events: {
'click .btn-primary': 'saveClient',
'focusout .loginname': 'usercheck'
},
usercheck: function() { //** not working
console.log("usercheck detected");
alert("Alerts suck.");
},
render: function(){
//Since our template has dynamic variables in it, we need to compile it
var compiledTemplate = _.template( RegisterTemplate, this.model );
this.$el.html(compiledTemplate); //Replaces EVERYTHING inside the <div
id="container">
this.$('#phone').mask('(999) 999-9999');
this.$('#phone2').mask('(999) 999-9999');
this.$('#zip').mask('99999');
$(function () { //** working
$("input,select,textarea").not("[type=submit]").jqBootstrapValidation();
});
$('.loginname').live("click", function () { //** not working
alert('AHHHHHH!');
});
$().acknowledgeinput({ // ** this works fine
success_color: '#00FF00',
danger_color: '#FF0000',
update_on: 'keyup'
});
Run Code Online (Sandbox Code Playgroud)
** 我在模糊事件中查看Chrome,输入名称为/ id = loginname
HTML我确实看到了带有id的elmement的模糊(Chrome说它的输入#loginname)确实附加了模糊事件.我稍微更改了我的代码,但它仍然没有触发.我从来不知道有骨干,如果它只是简单的东西或其中一个"这个和范围"的问题:)
<div id="container" class="row-fluid">
<div class="span6">
<div class="requiredNotice"><i class="icon-warning-sign icon-red"></i> Can't
be blank!</div>
<h3>New Client Registration:</h3>
<form class="form-horizontal" method="POST">
<fieldset>
<div class="control-group">
<label class="control-label required" for="loginname">UserID (Email
</label>
<div class="controls">
<div class="input-prepend" data-role="acknowledge-input">
<div data-role="acknowledgement"><i></i></div>
<input type="email" data-type="email" required="required"
placeholder="Use email account"
maxlength="254" name="loginname" id="loginname"
class="inputclass pageRequired
input-xlarge" />
</div>
<span class="loginname_error label label-info hide"></span>
</div>
</div> ... etc
events: {
'click .btn-primary' : 'saveClient',
'focusout #input.loginname' : 'userCheck'
// "blur input.loginname" : "userCheck"
},
userCheck: function(e) {
console.log("usercheck detected");
alert("Alerts suck.");
},
Run Code Online (Sandbox Code Playgroud)
.live这里不需要,你的事件哈希也没有问题.模板可能有些问题.我只是focusout在这个jsfiddle中隔离了输入字段和事件,它工作得很好.
<script type="text/template" id="formtemplate">
<form>
<input type="text" class="loginname" value="" placeholder="enter login"/>
</form>
</script>
Run Code Online (Sandbox Code Playgroud)
...
var View = Backbone.View.extend({
events:{
'focusout .loginname':'checkUser'
},
render:function(){
this.$el.html($('#formtemplate').html());
},
checkUser:function(e){
alert('checkUser'); //works well
}
});
var view = new View();
view.render();
view.$el.appendTo('body');
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11411 次 |
| 最近记录: |