简单的按钮点击骨干 [英] Simple button click in backbone

查看:81
本文介绍了简单的按钮点击骨干的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用骨干网进行各种功能测试,但遇到了一个奇怪的问题.我正在尝试通过主干提交表单.我以前已经这样做过,但是我找不到我做的事情有什么问题.

I am trying out different functionalities using backbone and i came accross a strange one. I am trying to submit a form through backbone. I had done this previously and i cannot find whats wrong with what i am doing.

代码如下:

HTML部分

   <div clas="loginpage"></div>
   <form class="login-user-form">
     <input type="text" name="name" id="name" placeholder="Enter Name"><br><br>
     <button type="submit" class="btn">Create</button>
   </form>

jQuery Part

var UserLogin = Backbone.View.extend({
   el:'.loginpage',
   initialize:function(){
   console.log("Login View Initialized");
 },
 events:{
   'submit .btn' : 'loginuser'
 },
 loginuser:function(){
   console.log("Login Clicked.");
   return false;
 }
});
var userlogin = new UserLogin();

我在控制台中收到登录视图初始化"消息.但是我无法使loginuser函数正常工作.该页面通过其默认的提交功能进行提交.

I get Login View Initialized message in console. But i cannot get the loginuser function to work. The page submits through its default submit functionality.

我在做什么错了?

推荐答案

1)loginpage不包含表单.修复:

1) loginpage doesn't contain the form. Fix:

<div class="loginpage">
  <form class="login-user-form">
    <input type="text" name="name" id="name" placeholder="Enter Name"><br><br>
    <button type="submit" class="btn">Create</button>
  </form>
</div>

2)

events : {
 'submit' : 'loginuser'
},

loginuser : function(){
  console.log("Login Clicked.");
  return false; // Stops default html form submission
}

这篇关于简单的按钮点击骨干的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆