小编Ian*_*len的帖子

Chrome(但不是Firefox)自动填充是重叠标签文本,尽管jquery

我已经创建了一个登录表单,其中包含"用户名"和"密码"的标签,下面的jquery用于在用户关注字段后隐藏标签.

$(document).ready(function(){

 $("form.login input")
  .bind("focus.labelFx", function(){
   $(this).prev().hide();
  })
  .bind("blur.labelFx", function(){
   $(this).prev()[!this.value ? "show" : "hide"]();
  })
  .trigger("blur.labelFx");

});
Run Code Online (Sandbox Code Playgroud)

和HTML:

<form method="post" id="login-form" action="/accounts/login/">
    <div class="input-wrapper">
        <label for="id_username">Username</label>
        <input id="id_username" size="30" type="text" name="username">
    </div>
</form>
Run Code Online (Sandbox Code Playgroud)

问题是chrome的自动完成似乎是在加载用户名和密码之前,这个脚本可以捕获它,给我奇怪的重叠文本,直到我手动关注它.这不是 Firefox的问题.图片来自:http://imgur.com/kJRLa

有关如何解决这个问题的建议,以便自动填充数据导致标签隐藏?

html javascript forms jquery google-chrome

9
推荐指数
2
解决办法
6772
查看次数

由于'redirect_to root_url'未传递操作而导致的RoutingError

使用Devise进行身份验证并使用CanCan进行授权的标准Rails_Admin安装,以非admin用户身份访问http:// localhost:3000/admin会生成以下服务器日志:

Started GET "/admin" for 127.0.0.1 at 2011-08-09 22:46:10 -0400
  Processing by RailsAdmin::MainController#index as HTML
  User Load (0.2ms)  SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1
Completed 404 Not Found in 151ms

ActionController::RoutingError (No route matches {:controller=>"gyms"}):
  app/controllers/application_controller.rb:5:in `block in <class:ApplicationController>'
Run Code Online (Sandbox Code Playgroud)

直到最后一部分的一切似乎都没问题.据我所知,CanCan可以正确地解救异常,并尝试通过以下代码重定向到root_url:

class ApplicationController < ActionController::Base
  protect_from_forgery

  rescue_from CanCan::AccessDenied do |exception|
    redirect_to root_url, :alert => exception.message
  end
end

TopOut::Application.routes.draw do
  mount RailsAdmin::Engine => '/admin', :as => 'rails_admin'
  devise_for :users

  resources :gyms

  root :to => "gyms#index" …
Run Code Online (Sandbox Code Playgroud)

cancan ruby-on-rails-3 rails-admin

5
推荐指数
1
解决办法
2691
查看次数

无法将JavaScript库加载到Meteor应用程序中

我在使用带有Meteor应用程序的fabric.js库时遇到了麻烦,不幸的是我无法完全将其添加到我的应用程序中,更不用说调用它了.最简单的娱乐活动如下:

> mrt create test
> cd test
> mkdir client
> curl -o ./client/all.js http://cdnjs.cloudflare.com/ajax/libs/fabric.js/1.2.0/fabric.all.min.js
> mrt
Run Code Online (Sandbox Code Playgroud)

转到localhost:3000会显示以下控制台输出:

Uncaught TypeError: Cannot read property 'object' of undefined    all.js:4074
global.fabric.global.fabric                                       all.js:4074
(anonymous function)                                              all.js:4936
(anonymous function)
Run Code Online (Sandbox Code Playgroud)

all.js的第4074行是第二行:

var fabric = global.fabric || (global.fabric = { }),
    extend = fabric.util.object.extend,
    capitalize = fabric.util.string.capitalize,
    clone = fabric.util.object.clone,
    toFixed = fabric.util.toFixed,
    multiplyTransformMatrices = fabric.util.multiplyTransformMatrices;
Run Code Online (Sandbox Code Playgroud)

我很确定我做错了(与织物或流星的问题相反)但我不确定在哪里.我也尝试将all.js文件放入我的公共目录中,虽然它没有抛出相同的TypeError,但它确实使得结构变量似乎在我的代码中的任何地方都不可用.

将fabric.js正确加载到我的应用程序中的任何帮助都会很棒.

javascript fabricjs meteor

5
推荐指数
1
解决办法
2706
查看次数

概率运动返回预期的不同结果

作为练习,我正在编写一个程序来计算使用相同数字滚动5个模具的几率.这个想法是通过模拟获得结果,而不是简单的数学.我的程序是这样的:

# rollFive.py

from random import *

def main():
    n = input("Please enter the number of sims to run: ")
    hits = simNRolls(n)
    hits = float(hits)
    n = float(n)
    prob = hits/n
    print "The odds of rolling 5 of the same number are", prob

def simNRolls(n):
    hits = 0
    for i in range(n):
        hits = hits + diceRoll()
    return hits


def diceRoll():
    firstDie = randrange(1,7,1)
    for i in range(4):
        nextDie = randrange(1,7,1)
        if nextDie!=firstDie:
            success = 0
            break
        else:
            success …
Run Code Online (Sandbox Code Playgroud)

python probability

2
推荐指数
1
解决办法
345
查看次数

在最终迭代中简单的'for'循环崩溃程序

下面的程序似乎每次都在最后崩溃,我假设这是因为一旦我到达i =(size-1),那么wordList [i + 1]将不会返回任何内容,返回null,或类似的东西.有什么方法吗?我纠正这是我问题的根源吗?

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>

using std::cin;
using std::cout;            using std::endl;
using std::sort;
using std::string;          using std::vector;

// Obtain a list of words and return the de-duped list
// with an accompanying word count
int main()
{
    cout << "Enter a series of words separated by spaces, "
            "followed by end-of-file: ";

    vector<string> wordList;
    string x;
    while (cin >> x)
          wordList.push_back(x);

    typedef vector<string>::size_type vec_sz;
    vec_sz size = wordList.size();
    if (size …
Run Code Online (Sandbox Code Playgroud)

c++ loops

1
推荐指数
1
解决办法
2804
查看次数