如果浏览器是 Chrome,我怎样才能在这个 jQuery 脚本中有不同的行为?
How can I have a different behaviour in this jQuery script if the browser is Chrome?
我完全是 JavaScript 和 jQuery 的新手,我遇到了以下问题。
我必须修改 jQuery 脚本,以便它在浏览器为 Chrome 时具有不同的行为。
这是我的脚本:
$(document).ready(function () {
$("thead.opening").click(function () {
alert("INTO second function");
$(this).next().css('width', '10000000 em');
alert(modified);
$(this).next().css('width', '10000000 em');
$(this).next().css('display', 'table-row-group');
alert($(this).next().css('display'));
});
});
如您所见,此脚本执行此语句来设置 显示:table-行组 CSS 设置:
我希望如果浏览器是 Chrome 脚本集:
$(this).next().css('display', 'block');
我可以通过某种方式做到吗?
您可以使用:
var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
$(this).next().css('display', is_chrome ? 'block' : 'table-row-group');
Find chrome browser : original post from SO
我完全是 JavaScript 和 jQuery 的新手,我遇到了以下问题。
我必须修改 jQuery 脚本,以便它在浏览器为 Chrome 时具有不同的行为。
这是我的脚本:
$(document).ready(function () {
$("thead.opening").click(function () {
alert("INTO second function");
$(this).next().css('width', '10000000 em');
alert(modified);
$(this).next().css('width', '10000000 em');
$(this).next().css('display', 'table-row-group');
alert($(this).next().css('display'));
});
});
如您所见,此脚本执行此语句来设置 显示:table-行组 CSS 设置:
我希望如果浏览器是 Chrome 脚本集:
$(this).next().css('display', 'block');
我可以通过某种方式做到吗?
您可以使用:
var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
$(this).next().css('display', is_chrome ? 'block' : 'table-row-group');
Find chrome browser : original post from SO