jQuery 在 Firefox 中定位不同的值
jQuery position different value in Firefox
我创建了以下 fiddle 来说明问题...
https://jsfiddle.net/scottieslg/q78afsu8/10/
如果我在 Chrome 或 Opera 中 运行 这个 fiddle,我得到一个值 8。
然而,当我在 Firefox 中 运行 它时,它返回为 9。
在 IE 中,我得到 8.5。
如何让所有浏览器都return使用相同的值?
Html
<table id='testTable'>
<thead>
<tr><td>Test</td></tr>
</thead>
<tbody>
<tr><td>Body</td></tr>
</tbody>
</table>
<div id='topPos'></div>
jQuery
$(document).ready(function() {
var topPos = $("#testTable tr:nth-child(1) td:first").position().top;
console.log(topPos);
$("#topPos").html("Top: " + topPos);
});
css
#testTable {
table-layout: fixed;
width: 100%;
padding: 0;
border-collapse: collapse;
}
#testTable thead tr td {
border: 1px solid #ccc;
}
首先尝试使所有元素相同。
* {margin:0;padding:0;}
我创建了以下 fiddle 来说明问题...
https://jsfiddle.net/scottieslg/q78afsu8/10/
如果我在 Chrome 或 Opera 中 运行 这个 fiddle,我得到一个值 8。
然而,当我在 Firefox 中 运行 它时,它返回为 9。
在 IE 中,我得到 8.5。
如何让所有浏览器都return使用相同的值?
Html
<table id='testTable'>
<thead>
<tr><td>Test</td></tr>
</thead>
<tbody>
<tr><td>Body</td></tr>
</tbody>
</table>
<div id='topPos'></div>
jQuery
$(document).ready(function() {
var topPos = $("#testTable tr:nth-child(1) td:first").position().top;
console.log(topPos);
$("#topPos").html("Top: " + topPos);
});
css
#testTable {
table-layout: fixed;
width: 100%;
padding: 0;
border-collapse: collapse;
}
#testTable thead tr td {
border: 1px solid #ccc;
}
首先尝试使所有元素相同。
* {margin:0;padding:0;}