小编Bar*_*eby的帖子

SASS:如何删除/*#sourceMappingURL注释

我从Windows命令行启动SASS手表.和FireFox开发人员工具栏(使用Show Sources)查看.scss文件.

一切正常,但我意识到我的最终.css输出文件添加了额外的最后一行,如:

/*# sourceMappingURL=index.css.map */
Run Code Online (Sandbox Code Playgroud)

在我的公司,我不允许留下这个评论我想知道如果我必须每次手动删除它或有任何方法自动删除它当我停止SASS Watch.

除了手动移除线路之外,问题在于我正在使用Git进行版本控制,因此只需启动SASS(--sass watch ...)将使我的.css文件显示为由GIT修改为额外的行被添加(因此它显示在要提交的文件中)

css comments sass

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

stopPropagation和live()方法.我错过了什么?

我已经阅读了jQuery doc,我知道如果我使用live()将事件绑定到元素上,使用stopPropagation()是没有意义的,因为带有live()的事件绑定到文档节点,因此事件已经被激活了.这么说,我认为nex代码会提醒3次,因为stopPropagation不会停止任何事情:

<ul style="border:red solid 1px;">
    <li style="padding:10px; border:blue solid 1px;">
        <p style="border:green solid 1px;"><a href="#">link</a></p>
    </li>
    <li style="padding:10px; border:blue solid 1px;">
        <p style="border:green solid 1px;">no link</p>
    </li>
</ul>

<script type="text/javascript">
    $('a').live( "click", function( e ) {alert("link");e.stopPropagation()} );
    $('ul').live( "click", function( e ) {alert("ul");} );
    $('ul li').live( "click", function( e ) {alert("li");} );
</script>
Run Code Online (Sandbox Code Playgroud)

当我点击链接时我预期并提醒"li"和"ul",但是当它应该是没用的时候,stopPropagation会停止其他事件.我错过了什么?

jquery events stoppropagation

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

如何从 IFRAME 中触发“beforeunload”事件

我有一个应用程序(命名为 B),它被另一个主应用程序(命名为 A 或父应用程序)嵌入到 Iframe 中。

So: App A--                     // domain of A: https://mydomain/mainApp
           |___ App B in Iframe // domain in B: https://mydomain/appB
Run Code Online (Sandbox Code Playgroud)

问题是:然后主/父应用程序有一个导航菜单。一个项目,当点击时,创建一个带有 SRC 属性的 Iframe,里面加载了 App B。

当用户点击应用 A 中菜单的另一个选项时,Iframe 被销毁,React 中出现另一个内容视图,替换 Iframe。

这样做时,用户在 B 中的表单中键入的所有数据都消失了,因为我无法触发 B 中的保存事件。

我在 iframe 应用程序中添加了以下事件处理程序:

window.addEventListener("beforeunload", function (e) {

    // Trigger here the save settigns event inside B
});
Run Code Online (Sandbox Code Playgroud)

但是当用户浏览主应用程序菜单时,以前的代码永远不会触发。正如我所看到的,App A 中的导航菜单会更改浏览器中的 URL(但似乎是 SPA React.js 路由或类似路由,没有真正的重定向)。

问题是:Iframe 能否检测到何时卸载/销毁以首先触发 Ajax 中的保存设置?PS:我无权访问 App A 代码。

提前致谢

javascript iframe iframe-app dom-events reactjs

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

在 NPM 脚本中找不到模块自动前缀

在 Windows 10 和 npm 版本 6.9.0 下,我无法让以下脚本运行:

"build:css": "postcss --use autoprefixer -b 'last 2 versions' < ./static/css/main.css"  
Run Code Online (Sandbox Code Playgroud)

我总是在 Windows 控制台中收到相同的错误,如下所示:

Plugin Error: Cannot find module 'autoprefixer'

我尝试将语法更改为以下语法,但没有结果:

"build:css": "postcss --use autoprefixer -b \"last 10 versions\" ./static/css/main.css -o ./static/css/main-prefixed.css"
Run Code Online (Sandbox Code Playgroud)

谁能告诉我这里有什么问题吗?老实说,我对这个 npm 脚本很陌生。

我的package.json看起来像这样:

{
  "name": "test-automate-npm",
  "version": "1.0.0",
  "description": "test",
  "main": "index.html",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "scss": "echo 'Compiling SCSS' && node-sass --watch scss -o ./static/css",
    "build": "npm run scss && …
Run Code Online (Sandbox Code Playgroud)

npm autoprefixer postcss npm-scripts

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

Require.js 甚至在 IF 语句中加载模块

我在通过 require.js 加载某些 .js 模块时发现了一些问题 问题是:我只需要加载某些页面中的某些模块,而不是整个网站。因此,我以这种方式放置代码:

if($('.module-news').length > 0 + $('.module-ticket-euromillones-multiple').length + $('.module-news-page').length > 0) {
            require('_modules/news-grid').init();
        }
Run Code Online (Sandbox Code Playgroud)

如果class="module-news"存在(新闻页面),则此代码在 HTML 中搜索。如果是这样,则使用 javascript 加载模块。

那是行不通的。IF 评估正确,但无论 .module-news 是否存在,模块news-grid总是在加载。

我发现如果我更改变量的模块路径字符串,则 requires 行为正确,但这没有意义。这如何,以下代码有效:

var name = "_modules/news-grid";

if($('.module-news').length > 0 + $('.module-ticket-euromillones-multiple').length + $('.module-news-page').length > 0) {
                require(name).init();
            }
Run Code Online (Sandbox Code Playgroud)

这是需要的已知问题吗?我错过了什么吗?(也许在 requirejs.config 设置中?

帮助表示赞赏

javascript jquery amd requirejs

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