小编Kop*_*lyf的帖子

如何在href javascript函数中获取调用元素?

我在html中有一个锚标记元素,如:

<a href="javascript:handleEvent(this, 'abc')"></a>
Run Code Online (Sandbox Code Playgroud)

现在在javascript函数中,我写了:

function handleEvent(sourceElement, txt) {
    console.log(sourceElement);
}
Run Code Online (Sandbox Code Playgroud)

在这种情况下,安慰元素将成为窗口.我尝试了sourceElement.document.activeElement,但它似乎不适用于chrome,它将作为body元素出现.

我无法将锚标记的结构更改为'onClick'函数,因为这来自其他一些来源.有没有办法在这种情况下找到调用元素?

html javascript anchor jquery href

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

Koa : koa-route 和 koa-mount 有什么区别。我应该什么时候使用?

我正在尝试使用 Koa.js,并检查了以下用于路由请求的模块: 1. koa-route 2. koa-mount

当我在 google 中查看他们的 github 页面/教程时,这些示例看起来几乎相似,但略有不同。

  1. 对于 koa 路线:

    var route = require('koa-route');
    app.use(route.get('/', index));
    
    //functions to handle the request
    function* index(){
        this.body = "this should be home page!";
    }
    
    Run Code Online (Sandbox Code Playgroud)
  2. 对于 koa-mount:

     //syntax to add the route
    var mount = require('koa-mount');
    var a = koa();
    app.use(mount('/hello', a));
    
    //functions to handle the request
    a.use(function *(next){
      yield next;
      this.body = 'Hello';
    });
    
    Run Code Online (Sandbox Code Playgroud)

在我看来唯一的区别是 mount 需要一个中间件来处理请求,而 route 需要一个生成器来处理请求。

我很困惑何时使用什么以及何时使用两者(在某些教程中看到过)?

node.js koa

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

在本地生产模式下运行rails

我正在尝试使用以下命令在生产模式下运行rails(不太了解它):

rails server -e production
Run Code Online (Sandbox Code Playgroud)

但是我在控制台和丑陋的页面中收到这些错误而没有加载css:

Resource interpreted as Stylesheet but transferred with MIME type text/html: "http://10.20.200.199:3000/".
(index):1 Refused to execute script from 'http://10.20.200.199:3000/javascripts/application.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.
(index):1 Refused to execute script from 'http://10.20.200.199:3000/logins/plugins.js?v=1' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.
Run Code Online (Sandbox Code Playgroud)

这种情况发生在我们正在使用的所有脚本中.

有人可以帮我解决这里可能出错的问题.

提前致谢.

ruby-on-rails production-environment

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

设置为外部单击时,角度引导下拉列表自动关闭不起作用

这是一个简单的下拉菜单,应该仅在外部单击时关闭。它曾经在早期版本(0.13)中工作。

难道我做错了什么。不想采取像停止传播和防止违约这样的解决办法。这是我最后的手段。

下面是一个简单下拉列表的 plunkr:

http://plnkr.co/edit/A2vDHb43PThalcHAhLkJ?p=preview

    <span class="dropdown" uib-dropdown auto-close="outsideClick">
      <a href="javascript:void(0);" class="dropdown-toggle" uib-dropdown-toggle>
        Click me for a dropdown, yo!
      </a>
      <ul class="dropdown-menu">
        <li>Element 1</li>
        <li>Element 2</li>
      </ul>
    </span>
Run Code Online (Sandbox Code Playgroud)

angularjs angular-bootstrap

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