【问题标题】:2 Bugs: Possible Cross-Browser Issues2 错误:可能的跨浏览器问题
【发布时间】:2014-06-04 05:24:51
【问题描述】:

我正在制作一个 JavaScript 游戏,遇到了 2 个问题,我将尝试详细描述这些问题。 (出现问题的网页是 jaminweb.com/Snake.html)。

首先是我的一个听众似乎没有工作。

我的head 中有script 标签之间,

$("#buttonname").click(function()
{
  alert("good ... the function was called.");
  s = new game(param1, param2, param3);
});

<button id="buttonname">Start Game</button>

在我的body 中,匿名函数没有被调用。它没有通过你看到的我设置的良好的 'ole alert 测试。加载页面时没有错误记录到控制台。

第二个问题是,虽然我的游戏在我的电脑上运行在谷歌 Chrome 上,但它在 Firefox 上不起作用,而且当我在家使用我的机器时,它在任何浏览器上都不起作用。当蛇与食物接触时,游戏没有正确检测到。我认为问题出在以下几行:

var height = Math.floor($("#somediv").height())+1; 
var width =  Math.floor($("#somediv").width())+1;

出于某种原因,我认为这些变量在某些浏览器上的计算方式不同。这可能是问题所在,我该如何解决?

【问题讨论】:

  • 你是否包含了 jquery 库?是 $(document).ready() 中包含的脚本,以确保 #buttonname 已加载到 html 中。
  • 另外,如果有控制台的错误,请提供。
  • 听@Adjit 并尝试var height = (Math.floor(parseInt($("#somediv").height()))+1); 否则JS 可能会尝试连接字符串而不是添加整数。

标签: javascript jquery html


【解决方案1】:

不知道这是否有帮助,但是如果您有带有超链接的按钮,则该地址将不起作用,因为 URL 使用您的计算机/用户名和保存它的文件名,所以说您这样做了。 ..

<button id="buttonname"> Start </button>

然后

    $("#buttonname").click(function()
{
  <!-- going to another page here the computer will not be able to find that page because of the user in the link: file:///C:/Users/UserName/Desktop/xxx%20stuff/Corn%20Puff%20Cereal.html
  s = new game(param1, param2, param3);
});

另一件事是“s”是一个变量,你之前声明过吗?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-25
    • 2013-06-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多