GVKun编程网logo

如何解决<select> 中 <option> 的 HTML 标题“提示”未显示在 mac OS chrome 浏览器上

我在使标题“提示”不显示在下拉选项中时遇到问题。这只发生在带有 Google chrome 的 Mac OS 上。

是否有解决此问题的方法?

代码片段/示例:

<select>
  <option title="hint for example 1">Example 1</option>
  <option title="hint for example 2">Example 2</option>
  <option title="hint for example 3">Example 3</option>
</select>

.Net Core Razor具有错误的文化 Option 1: Manually install cldr scripts Option 2: Use LocalizationValidationScripts taghelper

.Net Core Razor具有错误的文化 Option 1: Manually install cldr scripts Option 2: Use LocalizationValidationScripts taghelper

如何解决.Net Core Razor具有错误的文化 Option 1: Manually install cldr scripts Option 2: Use LocalizationValidationScripts taghelper

我有一个本地化的.Net Core 3应用程序。我的资源在.resx文件中的单独程序集中。本地化设置为使用如下cookie:

var cultureProvider = new CookieRequestCultureProvider();
cultureProvider.CookieName = "MyCultureCookie";

var localizationoptions = new RequestLocalizationoptions
{
    DefaultRequestCulture = new RequestCulture("de"),SupportedCultures = StaticData.SupportedCultures,SupportedUICultures = StaticData.SupportedCultures,RequestCultureProviders = new List<IRequestCultureProvider> 
    { 
        cultureProvider,new AcceptLanguageHeaderRequestCultureProvider()
    }
};

app.UseRequestLocalization(localizationoptions);

并本地化验证消息:

services.AddLocalization(options => options.ResourcesPath = "Resources");
services.AddControllersWithViews()
    .AddDataAnnotationsLocalization(options =>
    {
        options.DataAnnotationLocalizerProvider = (type,factory) =>
            factory.Create(typeof(MyLocalizationDll));
    })
    .AddViewLocalization()
    .AddRazorRuntimeCompilation();
services.AddMvc()
    .SetupModelBindingLocalization(services)
    .AddViewLocalization();

我认为输入是

<input type="number"min="0" max="100" step="0.1" />

效果很好,我可以切换语言,包括几乎所有数据验证错误消息在内的所有页面文本都将被翻译,数字以正确的格式显示(例如,“ en”为1.00,“ de”为1.00)。

但是问题是:当我在德国文化中有一个小数,例如1,5并提交了表格时,则在我的控制器中为15。仅当我将语言切换为“ en”时,我才获得正确的数字,因为十进制分隔符正好符合预期。我还用其他语言获得了该字段的一些验证消息。只是不知道这里是什么问题...

解决方法

自定义模型活页夹可能提供解决此问题的方法,但是如果您需要更好的方法,则必须安装一组cldr脚本来进行数字/日期/货币/等验证。

Option 1: Manually install cldr scripts

  • 安装cldr库:
{
  "version": "1.0","defaultProvider": "jsdelivr","libraries": [
    {
      "library": "cldrjs@0.5.1","destination": "wwwroot/lib/cldr"
    },{
      "library": "cldr-data@35.1.0","destination": "wwwroot/lib/cldr-data"
    },{
      "library": "globalize@1.4.2","destination": "wwwroot/lib/globalize"
    }
  ]
}
  • 打开wwwroot/lib/cldr-data/package.json文件,并在最后一个结束括号之前添加以下代码:
"peerDependencies": {
    "cldr-data": ">=26"
  }
  • 在要使用十进制验证的地方使用脚本:
<!-- cldr scripts (needed for globalize) -->
<script src="/lib/cldr/dist/cldr.min.js"></script>
<script src="/lib/cldr/dist/cldr/event.min.js"></script>
<script src="/lib/cldr/dist/cldr/supplemental.min.js"></script>

<!-- globalize scripts -->
<script src="/lib/globalize/dist/globalize.min.js"></script>
<script src="/lib/globalize/dist/globalize/number.min.js"></script>
<script src="/lib/globalize/dist/globalize/date.min.js"></script>
<script src="/lib/globalize/dist/globalize/currency.min.js"></script>

<!-- this file can be downloaded from : -->
<!-- https://github.com/johnnyreilly/jquery-validation-globalize -->
<script src="https://cdn.jsdelivr.net/gh/johnnyreilly/jquery-validation-globalize@1.0.0/jquery.validate.globalize.min.js"></script>

<!-- code to get check if current cultures scripts are exists -->
<!-- if not,select parent cultures scripts -->
@inject Microsoft.AspNetCore.Hosting.IHostingEnvironment HostingEnvironment
@{
    string GetDefaultLocale()
    {
        const string localePattern = "lib\\\\cldr-data\\\\main\\\\{0}";
        var currentCulture = System.Globalization.CultureInfo.CurrentCulture;
        var cultureToUse = "en"; //Default regionalisation to use

        if (System.IO.Directory.Exists(System.IO.Path.Combine(HostingEnvironment.WebRootPath,string.Format(localePattern,currentCulture.Name))))
            cultureToUse = currentCulture.Name;
        else if (System.IO.Directory.Exists(System.IO.Path.Combine(HostingEnvironment.WebRootPath,currentCulture.TwoLetterISOLanguageName))))
            cultureToUse = currentCulture.TwoLetterISOLanguageName;

        return cultureToUse;
    }
}

<script type="text/javascript">
    var culture = "@GetDefaultLocale()";
    $.when(
        $.get("/lib/cldr-data/supplemental/likelySubtags.json"),$.get("/lib/cldr-data/main/" + culture + "numbers.json"),$.get("/lib/cldr-data/main/" + culture + "/currencies.json"),$.get("/lib/cldr-data/supplemental/numberingSystems.json"),$.get("/lib/cldr-data/main/" + culture + "/ca-gregorian.json"),$.get("/lib/cldr-data/main/" + culture + "/timeZoneNames.json"),$.get("/lib/cldr-data/supplemental/timeData.json"),$.get("/lib/cldr-data/supplemental/weekData.json"),).then(function () {
        // Normalize $.get results,we only need the JSON,not the request statuses.
        return [].slice.apply(arguments,[0]).map(function (result) {
            return result[0];
        });
    }).then(Globalize.load).then(function () {
        Globalize.locale(culture);
    });
</script>

Option 2: Use LocalizationValidationScripts taghelper

此标记帮助器以简单的方式提供了上述解决方案。

  • 从nuge安装LazZiya.TagHelpers
PM > Install-Package LazZiya.TagHelpers
  • 注册启动
@using LazZiya.TagHelpers

services.AddTransient<ITagHelperComponent,LocalizationValidationScriptsTagHelperComponent>();
  • 添加到_ViewImports.cshtml
@addTagHelper *,LazZiya.TagHelpers
  • 在部分验证脚本之后,在“脚本”部分中插入html标记
@section Scripts {
    <partial name="_ValidationScriptsPartial" />
    <localization-validation-scripts></localization-validation-scripts>
}
  • How to install client side validation scripts
  • Valdiating Localized Input in Asp.Net Core

antd 自定义 className 未显示在 Chrome 开发工具中

antd 自定义 className 未显示在 Chrome 开发工具中

如何解决antd 自定义 className 未显示在 Chrome 开发工具中

我正在使用 antd 并且想为组件添加一个 className 来编辑组件的 css 样式,以下是我的代码:

events.js

import styles from "./index.less";

<List
  className={styles.events_list}
  itemLayout="vertical"
  size="large"
>
  <List.Item
    className={styles.event_list_item}
    key={item.title}
  />
</List>

无索引

.event_list_item {
    :global {
        background-color: red;
    }
}

.events_list {
    font-size: 16px;
}

我正在向 List 和 List.Item 添加一个 className,但是当我打开 Chrome 开发工具元素时,我在那里没有看到添加的类名。 下面是截图。

enter image description here

解决方法

events.js

import styles from "./index.less";

<List
  className=''event_list_item''
  itemLayout="vertical"
  size="large"
>
  <List.Item
    className=''event_list_item''
    key={item.title}
  />
</List>

无索引

.event_list_item {
    :global {
        background-color: red;
    }
}

.events_list {
    font-size: 16px;
}

或者你打算使用styles.events_list,你可以使用样式代替className

<List
  style={styles.events_list}
  itemLayout="vertical"
  size="large"
>
  <List.Item
    style={styles.event_list_item}
    key={item.title}
  />
</List>

谢谢

Chrome 扩展 - 如何使用 manifest v3 访问本地 file:// 解决方法:文件系统 API,Chrome 88-90解决方案 1. 扩展框架,Chrome 91+解决方案 2. 扩展窗口/选项卡,Chrome 91+注意事项

Chrome 扩展 - 如何使用 manifest v3 访问本地 file:// 解决方法:文件系统 API,Chrome 88-90解决方案 1. 扩展框架,Chrome 91+解决方案 2. 扩展窗口/选项卡,Chrome 91+注意事项

如何解决Chrome 扩展 - 如何使用 manifest v3 访问本地 file:// 解决方法:文件系统 API,Chrome 88-90解决方案 1. 扩展框架,Chrome 91+解决方案 2. 扩展窗口/选项卡,Chrome 91+注意事项

我有一个 Chrome 扩展程序,它可以(如果您允许访问文件 URL)抓取您在 chrome 中打开的本地 pdf 文件,并将其发送到我们的 API 进行处理。这是通过从后台脚本中获取带有 XMLHttpRequestfile:///Users/user/whatever/testfile.pdf 的 pdf 来完成的。

当为 Chrome 扩展程序迁移到 manifest v3 时,后台脚本将成为服务工作者。在 Service Worker 中,只有 fetch 可用,而不是 XMLHttpRequest。问题是,fetch 只支持 http 和 https,不支持 file:// url。那么,我如何才能实现让 Chrome 扩展程序获取/获取本地文件的相同功能?

编辑:我也尝试过的事情:

  1. 按照回答的建议从注入的 iframe 中创建 XMLHttpRequest。 发出请求时会出现错误 net:ERR_UNKNowN_URL_SCHEME

    net:ERR_UNKNOWN_URL_SCHEME

  2. 从注入的内容脚本生成 XMLHttpRequest。 这给出了错误 Access to XMLHttpRequest at ''file:///.../testfile1.docx.pdf'' from origin ''null'' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http,data,chrome,chrome-extension,chrome-untrusted,https.

    Access to XMLHttpRequest at ''file:///Users/clara.attermo/Downloads/testfile1.docx.pdf'' from origin ''null'' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http,https.

据我从大量研究中了解到,对 file:// 的访问通常被阻止,Chrome 扩展程序后台脚本曾经是一个例外。在我看来,内容脚本或操作弹出窗口从未允许这样做。

我的 manifest.json 供参考:

{
  "manifest_version": 3,"name": "..","version": "0.1","icons": {
    "16": "assets/icon-16x16.png","48": "assets/icon-48x48.png","128": "assets/icon-128x128.png"
  },"action": {
    "default_title": ".."
  },"background": {
    "service_worker": "background.js"
  },"permissions": [
    "webRequest","activeTab","scripting","storage","unlimitedStorage","identity","pageCapture"
  ],"host_permissions": [
    "<all_urls>"
  ],"web_accessible_resources": [{
    "resources": ["iframe.html"],"matches": [],"extension_ids": []
  }]
}

以编程方式注入内容脚本(使用 webextension-polyfill 进行 promise 支持)

browser.action.onClicked.addListener(async (tab: Tab) => {
  await browser.scripting.executeScript({files: [ "inject.js" ],target: {tabId: tab.id}});
});

解决方法

由于您已经提到的原因,您无法在后台 Service Worker 中执行此操作。还有一个 bug 阻止在正常可见的 chrome-extension:// 页面或 iframe 中执行此操作。它已在 Chrome 91 中修复。

解决方法:文件系统 API,Chrome 88-90

ManifestV3 扩展可以使用新的 File System API 来读取文件的内容,例如在通过 web_accessible_resources 公开的 iframe 内。

解决方案 1. 扩展框架,Chrome 91+

使用在带有该 pdf 的选项卡中运行的内容脚本:

    manifest.json 中的
  1. matches 应该包含 <all_urls>file://*/* 并且文件访问应该由用户在 chrome://extensions 扩展程序的 UI。或者你可以使用 activeTab 权限和 programmatic injection 当用户 单击您的扩展程序的图标或通过上下文菜单调用它。
  2. 内容脚本添加了一个不可见的 iframe,指向 web_accessible_resources 中公开的 iframe.html 文件
  3. iframe.html 加载 iframe.js,它照常使用 XMLHttpRequest。由于 iframe 具有 chrome-extension:// URL,因此它的环境 与旧的后台脚本相同,因此您可以执行所有操作 你之前在那里做过。

解决方案 2. 扩展窗口/选项卡,Chrome 91+

另一种解决方案是使用您的任何其他可见页面 扩展程序,如 action 弹出窗口或选项页面或任何其他 chrome-extension:// 属于您的扩展程序的页面,因为它们可以 只需访问 file:// 网址 就像您之前在后台脚本中所做的那样。

注意事项

  • 应该在 chrome://extensions 页面中为此扩展程序启用文件访问。

how to show new select input only when select specific option and when select another options don't show by jquery?拉拉维尔

how to show new select input only when select specific option and when select another options don't show by jquery?拉拉维尔

如何解决how to show new select input only when select specific option and when select another options don''t show by jquery?拉拉维尔

i''m trying to show new select input contains (states) options,when user select specific option a (USA) country,and when select another country non (USA) don''t show the states select options i want in this案件仍然隐藏。

路线

Route::get(''/ajax-form'',[AjaxController::class,''index''])->name(''ajax.index'');
Route::get(''/getState/{id}'',''getState''])->name(''ajax.state'');

控制器

class AjaxController extends Controller
{
    public function index()
    {
        $countries[''data''] = Country::orderby(''name'')
            ->select(''id'',''name'')
            ->get();

        return view(''ajax.index'',compact(''countries''));
    }
    
    public function getState($countryId = 0)
    {
        $states[''data''] = State::orderby(''name'')
            ->select(''id'',''name'')
            ->where(''country_id'',$countryId)
            ->get();

        return response()->json($states);
    }

带脚本的刀片形式:

@extends(''layouts.app'')
    
@section(''form'')
<form>
  <div>
    <div>
      <label for="inputCountry">Country</label>
      <selectid="inputCountry">
        <option selected>Choose...</option>
        @if ($countries[''data''] && $countries[''data'']->count() > 0)
          @foreach ($countries[''data''] as $country)
            <option value="{{ $country->id }}">{{ $country->name }}</option>
          @endforeach
        @endif
      </select>
    </div>
  </div>
  <div id="stateShow">
    <div>
      <label for="inputState">State</label>
      <select id="inputState">
        <option value=''0'' selected>Choose...</option>
      </select>
    </div>
  </div>
  <button type="submit">Save</button>
</form>
@stop

@section(''script'')
<script type="text/javascript">
  $(document).ready(function () {
    $(''#inputCountry'').change(function() {
      var id = $(this).val();
      // Empty the States dropdown without first
      $(''#stateShow'').show();
      $(''#inputState'').find(''option'').not('':first'').remove();
      // ajax request
      $.ajax({
        url: ''getState/'' + id,type:''get'',dataType: ''json'',success: function(response) {
          var len = 0;
          if(response[''data''] != null) {
            len = response[''data''].length;
          }
          if(len > 0) {
            // Read data in the state option that related with country
            for(var i = 0; i < len; i++) {
              var id = response[''data''][i].id;
              var name = response[''data''][i].name;
              var option = "<option value=''" + id + "''>" + name + "</option>";
              $(''#inputState'').append(option);
            }
          }
        }
      });
    });
  });
</script>
@stop

上面的脚本做,当我选择任何国家时,隐藏的(州)选择被显示,我希望它只在我选择(美国)而不是仍然隐藏的时候显示

你能帮我吗

解决方法

在您的 inputCountry 选择框中,我假设 {{ $country->name }} 是国家/地区名称,因此您可以使用 $(this).find("option:selected").text() 获取此值,然后将其与 USA 进行比较(如果它们是)等于显示你的 div 否则隐藏它。

演示代码

$(''#inputCountry'').change(function() {
  var id = $(this).val();
  var text = $(this).find("option:selected").text().trim() //get text
  if (text == "USA") {
    $(''#stateShow'').show(); //show
    $(''#inputState'').find(''option'').not('':first'').remove();
    //your ajax call put here ....
  } else {
    $(''#stateShow'').hide(); //hide
  }
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<form>
  <div>
    <div>
      <label for="inputCountry">Country</label>
      <selectid="inputCountry">
        <option selected>Choose...</option>
        <option value="{{ $country->id }}">Abc</option>
        <option value="{{ $country->id }}">USA</option>
      </select>
    </div>
  </div>
  <div id="stateShow">
    <div>
      <label for="inputState">State</label>
      <select id="inputState">
        <option value=''0'' selected>Choose...</option>
      </select>
    </div>
  </div>
  <button type="submit">Save</button>
</form>

今天的关于