相关疑难解决方法(0)

为什么在使用document.write()编写<script>标记时将其拆分?

为什么有些网站(或提供客户端javascript代码的广告客户)采用了在通话中拆分<script>和/或</script>标记的技术document.write()

我注意到亚马逊也这样做了,例如:

<script type='text/javascript'>
  if (typeof window['jQuery'] == 'undefined') document.write('<scr'+'ipt type="text/javascript" src="http://z-ecx.images-amazon.com/images/G/01/javascripts/lib/jquery/jquery-1.2.6.pack._V265113567_.js"></sc'+'ript>');
</script>
Run Code Online (Sandbox Code Playgroud)

html javascript

263
推荐指数
5
解决办法
12万
查看次数

Chrome Uncaught语法错误:意外令牌ILLEGAL

可能重复:
SyntaxError:意外的标记ILLEGAL

Chrome尝试在页面上加载脚本文件时收到主题错误.它说这是在javascript文件的最后一行.我似乎无法找到任何错误.firefox中没有错误,脚本按预期工作.只需使用表单验证

// JavaScript Document
$(function() {
  $('#wm-form').submit(function() {
    var errors = false;
    var errorMsg = "";
    $('.required').each(function() {
      if(!validField($(this))) {
        errorMsg += $(this).attr('name').capitalize() + " cannot be blank\n";
        errors = true;
      }
    });
    var emailAddress = $('#email');
    if(isValid(emailAddress) && !(/^(([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5}){1,25})+([;.](([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5}){1,25})+)*$/.test(emailAddress.val()))) {
      errorMsg += "Not a valid email address. Please enter in a correctly formatted email address";
      errors = true;
    }
    if(errors) {
      alert(errorMsg);
      return false;
    }
  });

  $('.form-focus').click(function() {
    $(document).scrollTop(0);
    $('#first_name').focus();
    return false;
  });
});

function validField(element) { …
Run Code Online (Sandbox Code Playgroud)

javascript jquery google-chrome

137
推荐指数
3
解决办法
44万
查看次数

JavaScript基于原型的继承的好例子

我用OOP语言编程已超过10年,但我现在正在学习JavaScript,这是我第一次遇到基于原型的继承.通过学习优秀的代码,我倾向于学得最快.什么是正确使用原型继承的JavaScript应用程序(或库)的精心编写的示例?您能否(简要地)描述原型继承的使用方式/原因,我知道从哪里开始阅读?

javascript prototypal-inheritance

88
推荐指数
7
解决办法
9万
查看次数

Vagrant/VirtualBox/Apache2奇怪的缓存行为

我正在使用Vagrant在Apache2上运行一个支持Ubuntu的VirtualBox.

除其他外,Web服务器提供来自my/vagrant目录的静态文件.

这在大多数情况下效果很好.但是,当我更改共享文件夹上的图像并重新加载网站时,会提供先前版本的图像,但它会被截断.

如果我先从共享文件夹中删除旧图片,刷新网站以便图片不显示,然后保存新文件并重新加载网站,它就可以工作.

有谁知道这个问题?我没有安装任何特殊功能,只有带有mod_rewrite的Apache 2和带有Mongo的AP,APC插件,MongoDB以及带有一堆脚本的nodeJS.

virtualbox apache2 vagrant

64
推荐指数
3
解决办法
2万
查看次数

webkit中的意外标记ILLEGAL

// if the box is outside the window, move it to the end
function checkEdge() {
    var windowsLeftEdge = $('#window').position().left;

    $('.box').each( function(i, box) {
        // right edge of the sliding box
        var boxRightEdge = $(box).position().left + $(box).width();

        // position of last box + width + 10px
        var newPosition = getNewPosition();

        if ( parseFloat(boxRightEdge) < parseFloat(windowsLeftEdge) ) { 
            $(box).css('left', newPosition);
            $(box).remove().appendTo('#window');
            first = $('.box:first').attr('class');
        }
    });
}? //Uncaught SyntaxError: Unexpected token ILLEGAL Occurs Here

// arrange the boxes to be aligned …
Run Code Online (Sandbox Code Playgroud)

javascript safari jquery google-chrome

61
推荐指数
4
解决办法
11万
查看次数

我的JS代码中的\ u200b(零宽度空格)字符.哪儿来的?

我正在使用NetBeans IDE 7.0.1开发Web应用程序的前端.最近我有一个非常讨厌的bug,我终于解决了.

说我有代码

var element = '<input size="3" id="foo" name="elements[foo][0]" />';
$('#bar').append(element);
Run Code Online (Sandbox Code Playgroud)

当我看到该size属性在Chrome中不起作用时(我没有在其他浏览器中检查过),我注意到出了问题.当我在Inspector中打开该元素时,它被解释为类似的东西

<input id="&quot;3&quot;" name="&quot;elements[foo][0]&quot;" 
    size="&quot;foo&quot;" />
Run Code Online (Sandbox Code Playgroud)

这很奇怪.手动重新键入element字符串字符后,错误消失了.当我撤消改变时,我注意到Netbeans在我的旧代码中提醒我一些Unicode字符.它是\u200b- 在每个'='之后,在'] ['之间和字符串末尾之间的零宽度空格.因此字符串看起来很正常,因为没有显示零宽度空格,但在转义它们之后我的字符串就是

'<input size=\u200b"3" id=\u200b"foo" name=\u200b"elements[foo]\u200b[0]" />\u200b'
Run Code Online (Sandbox Code Playgroud)

我到底在哪里得到它们?

我不知道我element从哪里复制了代码,但它绝对是以下之一:

  • Netbeans编辑器的其他窗格,带有HTML模板文件;
  • Google Chrome Inspector,"复制为HTML"操作;
  • Google Chrome源视图页面(非常值得怀疑).

但我无法用这两种方法重现这个错误.

我在Windows 7下使用Netbeans 7.0.1和Google Chrome 13.0.没有键盘切换器或类似的东西在运行.此外,我正在使用Git进行版本控制,但我没有提取该代码,因此Git不太可能受到责备.这对我的同事来说不是一个愚蠢的玩笑,因为他们非常有礼貌.

有什么建议搞砸了我的代码?

html javascript unicode netbeans google-chrome

43
推荐指数
3
解决办法
4万
查看次数

SyntaxError:Web Component Tester注释时出现意外的标记ILLEGAL

我使用Codeship 基于Polymer入门套件v1.1测试我的项目.

当我npm test在测试管道内运行时,我看到以下错误:

> @ test /home/rof/src/github.com/TFarla/night-live
> gulp test:local

/home/rof/src/github.com/TFarla/night-live/node_modules/browser-sync/node_modules/lodash/index.js:8404
/**
^^^

SyntaxError: Unexpected token ILLEGAL
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:413:25)
at Object.Module._extensions..js (module.js:452:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at Object.<anonymous> (/home/rof/src/github.com/TFarla/night-live/node_modules/browser-sync/lib/hooks.js:3:20)
at Module._compile (module.js:434:26)
at Object.Module._extensions..js (module.js:452:10)
npm ERR! Test failed.  See above for more details.
Run Code Online (Sandbox Code Playgroud)

以下是设置命令:

# By default we use the Node.js version set in your package.json or the latest
# …
Run Code Online (Sandbox Code Playgroud)

unit-testing node.js codeship web-component-tester polymer-1.0

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

如何从字符串中删除控制字符?

我的页面上有表单,用户可以在其中键入一些文本并提交.然后将文本发送到服务器(node.js上的REST API)并保存到DB(postgres).

问题是偶尔会将一些奇怪的字符(控制字符)保存到DB中 - 例如转义控制字符(^ [)或退格控制字符(^ H).通常它不会破坏任何东西,因为这些字符是不可见的,所以html正确呈现.但是,当我为RSS阅读器提供xml内容时,它们(阅读器)会因为这些控制字符而返回"格式错误的XML"(删除后它们会起作用).

我的问题是我如何从客户端级别(javascript)或服务器级别(javascript/node.js)的字符串中删除这些字符?

html javascript

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

Coffeescript意外的令牌是ILLEGAL,但不应该有任何违法行为

这真是令人生气.我在我的代码中找不到任何我正在做任何非法行为的地方,但出于某种原因,调用会fork炸毁我的程序.这是代码.相关部分位于我打电话的svgToPNG fork.

{fork} = require 'child_process'
{Coral} = require 'coral'

svgToPNG = (svg, reply, log) ->
  log "converting SVG to a PNG"
  # set up a child process to call convert svg: png:-
  convert = fork '/usr/bin/env', ['convert', 'svg:', 'png:-']
  log "Spawned child process running convert, pid " + convert.pid
  # set up behavior when an error occurs
  convert.stderr.on "data", ->
    log "Error occurred while executing convert"
    reply "error"
  # set up behavior for when we successfully …
Run Code Online (Sandbox Code Playgroud)

javascript coffeescript

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

为什么这段代码抛出ReferenceError:test没有定义?

var te?st = 1
console.log(test)
Run Code Online (Sandbox Code Playgroud)

尝试运行这个简单的代码.它给出了错误:ReferenceError: test is not defined尽管我定义了该变量.为什么会这样?

javascript unicode language-features language-design referenceerror

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