我正忙着编写一小段代码,该代码应该允许跨浏览器使用边框框模型。到目前为止,基本功能运行良好,但我无法让余量发挥作用。它应该适应可用的空间,但控制台返回 NaN,我不知道它来自哪里。
Here是一把 fiddle 。
console.log 甚至没有记录任何内容,我不知道为什么。非常感谢任何帮助。
最佳答案
在你的 fiddle 的许多部分都有这种模式:
($(this).css("border-left-width") * 2).replace("px", "")
您试图在执行乘法之后删除px
,这会导致语法错误。应该是
($(this).css("border-left-width").replace("px", "") * 2)
通过自动类型转换工作或
(parseInt($(this).css("border-left-width"), 10) * 2)
它将字符串解析为整数,删除尾随的 px
:
If
parseInt
encounters a character that is not a numeral in the specified radix, it ignores it and all succeeding characters and returns the integer value parsed up to that point.parseInt
truncates numbers to integer values. Leading and trailing spaces are allowed.
关于jquery - jQuery 中的左边框宽度返回 NaN,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12232056/