本文介绍了Zurb Foundation交换不起作用,'nodeName'未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用交换功能来根据屏幕尺寸更改图像.

I'm trying to use interchange to change images based on the screen size.

但是,初始化交换时,不会加载任何图像.然后,当我调整浏览器的大小(1024像素及更低)时,控制台出现错误:

However, when interchange is initialised no images load. Then when I resize the browser (1024px and lower) I get an error in the console saying:

Uncaught TypeError: Cannot read property 'nodeName' of undefined

与Foundation.interchange.js的第47行有关,即:

Which relates to line 47 of foundation.interchange.js, which is:

if (/IMG/.test(el[0].nodeName)) {

我要使用的代码是:

<img data-interchange="[http://www.example.com/image.png, (default)], [http://www.exmaple.com/image-large.png, (large)]" />

根据Zurb的文档,这是完全标准的.我已经确定图像存在,并且确实存在.

This is completely standard as per Zurb's documentation. I've made sure the images exist, which they do.

我正在使用Foundation版本5.2.2.

I'm using Foundation version 5.2.2.

有什么想法吗?

推荐答案

我遇到了这个问题,并通过进行一些简单的测试解决了该问题...

I had this issue and resolved it by doing some simple tests...

尝试以下方法:

  1. 检查-您仅调用脚本路径"interchange.js"的一个实例
  1. Check - You are only calling one instance of the script path 'interchange.js'

为什么? -这将确保您避免插件内重复的函数调用.

Why? - This will ensure that you avoid duplicate function calls within the plugin.

如何? -Ctrl-f(在视图源页面上)找到"interchange.js"一词

How? - Ctrl-f (find) the word 'interchange.js' on the view source page

这是检查它的最佳方法,尤其是当您在MVC或嵌套的Webforms框架中工作时.

This is the best way to check for it, especially if you're working in an MVC or nested webforms framework.

  1. 检查-$(document).foundation();在interchange.js脚本加载后调用
  1. Check - $(document).foundation(); is called after the interchange.js script has loaded

例如在此订单中....

eg. IN THIS ORDER....

<script src="/foundation/foundation.js")></script>
<script src="/foundation/foundation.interchange.js"></script>

<script type="text/javascript">
    $(document).ready(function () {

        $(document).foundation();

     });
</script>

为什么? -我相信一旦建立基础,交换就已经存在.

Why? - The interchange needs to exist already once foundation intializes I believe.

我希望这些选项对您有所帮助-抱歉,如果有点基本-还是值得一试干杯

I hope these options help - sorry if it's a bit basic - but worth a try all the sameCheers

这篇关于Zurb Foundation交换不起作用,'nodeName'未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 12:51