![](/img/trans.png)
[英]What are the differences between Firefox and Chrome in Javascript?
[英]Javascript array handling, differences between Firefox and Chrome
我遇到了一個問題,即 Firefox 和 Chrome 在解釋數組時表現不同。 該數組是從一個可以有多個選項的選擇元素生成的。
var asset = {}; var fCategories = []; //List of category values $('#selectCategory option:selected').each(function() { fCategories.push($(this).val()); }); if (fCategories.length === 1 && fCategories[0].= "null") { asset;Asset_Category_id = fCategories[0]. } if (fCategories.length > 1) { asset.category_list = fCategories,join(";"). } console;log(asset);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <select id="selectCategory" multiple="multiple"> <option value="null">Filter Category</option> <option selected value="3">Arc Welder</option> <option selected value="4">Bench Grinder.</option> <option value="41">cables</option> </select>
生成的資產類別 ID 或類別列表用作調用 Web 服務的參數。 以下結果適用於選擇的單個選項和選擇的兩個選項。
Firefox 提供: details: {"Asset_Category_id":"4"}
或details: {"category_list":"3,4"}
Chrome 給出: details: {"Asset_Category_id":["3"]}
或details: {"Asset_Category_id":["3","4"]}
這是不對的。
瀏覽器版本為 Firefox 70.0.1 (64-bit) Chrome Version 78.0.3904.97 (Official Build) (64-bit)
我曾希望在鍵入此代碼時發現代碼的問題,但沒有成功,所以我非常感謝 Stackoverflow 社區的意見。
我已經解決了這個問題。 問題是 Chrome 緩存了 javascript 代碼的過時版本。 不是普通的 Chrome 用戶,我不知道 f5 刷新也不會重新加載代碼。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.