簡體   English   中英

如果瀏覽器是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-row-group CSS settings:

如果瀏覽器是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');

查找Chrome瀏覽器:SO的原始帖子

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM