pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

  • <tfoot id='PSeZL'></tfoot><legend id='PSeZL'><style id='PSeZL'><dir id='PSeZL'><q id='PSeZL'></q></dir></style></legend>
      1. <small id='PSeZL'></small><noframes id='PSeZL'>

        <i id='PSeZL'><tr id='PSeZL'><dt id='PSeZL'><q id='PSeZL'><span id='PSeZL'><b id='PSeZL'><form id='PSeZL'><ins id='PSeZL'></ins><ul id='PSeZL'></ul><sub id='PSeZL'></sub></form><legend id='PSeZL'></legend><bdo id='PSeZL'><pre id='PSeZL'><center id='PSeZL'></center></pre></bdo></b><th id='PSeZL'></th></span></q></dt></tr></i><div class="j0vnmlz" id='PSeZL'><tfoot id='PSeZL'></tfoot><dl id='PSeZL'><fieldset id='PSeZL'></fieldset></dl></div>
          <bdo id='PSeZL'></bdo><ul id='PSeZL'></ul>

        Javascript 等價于 python 的 .format()

        Javascript equivalent to python#39;s .format()(Javascript 等價于 python 的 .format())

              <tbody id='09qwz'></tbody>
          1. <legend id='09qwz'><style id='09qwz'><dir id='09qwz'><q id='09qwz'></q></dir></style></legend>
              <tfoot id='09qwz'></tfoot>

              <i id='09qwz'><tr id='09qwz'><dt id='09qwz'><q id='09qwz'><span id='09qwz'><b id='09qwz'><form id='09qwz'><ins id='09qwz'></ins><ul id='09qwz'></ul><sub id='09qwz'></sub></form><legend id='09qwz'></legend><bdo id='09qwz'><pre id='09qwz'><center id='09qwz'></center></pre></bdo></b><th id='09qwz'></th></span></q></dt></tr></i><div class="rzv35dv" id='09qwz'><tfoot id='09qwz'></tfoot><dl id='09qwz'><fieldset id='09qwz'></fieldset></dl></div>

                <bdo id='09qwz'></bdo><ul id='09qwz'></ul>
                • <small id='09qwz'></small><noframes id='09qwz'>

                • 本文介紹了Javascript 等價于 python 的 .format()的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  限時送ChatGPT賬號..

                  我想要一個模仿 python .format() 函數的 javascript 函數

                  I would like a javascript function that mimics the python .format() function that works like

                  .format(*args, **kwargs)
                  

                  上一個問題為 '.format(*args) 提供了一個可能(但不完整)的解決方案

                  A previous question gives a possible (but not complete) solution for '.format(*args)

                  JavaScript 等效于 printf/string.format

                  我希望能夠做到

                  "hello {} and {}".format("you", "bob"
                  ==> hello you and bob
                  
                  "hello {0} and {1}".format("you", "bob")
                  ==> hello you and bob
                  
                  "hello {0} and {1} and {a}".format("you", "bob",a="mary")
                  ==> hello you and bob and mary
                  
                  "hello {0} and {1} and {a} and {2}".format("you", "bob","jill",a="mary")
                  ==> hello you and bob and mary and jill
                  

                  我意識到這是一項艱巨的任務,但也許在某個地方有一個完整(或至少部分)的解決方案,其中也包括關鍵字參數.

                  I realize that's a tall order, but maybe somewhere out there is a complete (or at least partial) solution that includes keyword arguments as well.

                  哦,我聽說 AJAX 和 JQuery 可能有這方面的方法,但我希望能夠在沒有所有開銷的情況下做到這一點.

                  Oh, and I hear AJAX and JQuery possibly have methods for this, but I would like to be able to do it without all that overhead.

                  特別是,我希望能夠將它與 google doc 的腳本一起使用.

                  In particular, I would like to be able to use it with a script for a google doc.

                  謝謝

                  推薦答案

                  更新:如果您使用的是 ES6,模板字符串的工作方式與 String.format 非常相似:https://developers.google.com/web/updates/2015/01/ES6-Template-字符串

                  UPDATE: If you're using ES6, template strings work very similarly to String.format: https://developers.google.com/web/updates/2015/01/ES6-Template-Strings

                  如果不是,以下適用于上述所有情況,其語法與 python 的 String.format 方法非常相似.下面是測試用例.

                  If not, the below works for all the cases above, with a very similar syntax to python's String.format method. Test cases below.

                  String.prototype.format = function() {
                    var args = arguments;
                    this.unkeyed_index = 0;
                    return this.replace(/{(w*)}/g, function(match, key) { 
                      if (key === '') {
                        key = this.unkeyed_index;
                        this.unkeyed_index++
                      }
                      if (key == +key) {
                        return args[key] !== 'undefined'
                        ? args[key]
                        : match;
                      } else {
                        for (var i = 0; i < args.length; i++) {
                          if (typeof args[i] === 'object' && typeof args[i][key] !== 'undefined') {
                            return args[i][key];
                          }
                        }
                        return match;
                      }
                    }.bind(this));
                  };
                  
                  // Run some tests
                  $('#tests')
                    .append(
                      "hello {} and {}<br />".format("you", "bob")
                    )
                    .append(
                      "hello {0} and {1}<br />".format("you", "bob")
                    )
                    .append(
                      "hello {0} and {1} and {a}<br />".format("you", "bob", {a:"mary"})
                    )
                    .append(
                      "hello {0} and {1} and {a} and {2}<br />".format("you", "bob", "jill", {a:"mary"})
                    );

                  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
                  <div id="tests"></div>

                  這篇關于Javascript 等價于 python 的 .format()的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  Browserify, Babel 6, Gulp - Unexpected token on spread operator(Browserify,Babel 6,Gulp - 傳播運算符上的意外令牌)
                  Is it possible to pass a flag to Gulp to have it run tasks in different ways?(是否可以將標志傳遞給 Gulp 以使其以不同的方式運行任務?)
                  Why do we need to install gulp globally and locally?(為什么我們需要在全局和本地安裝 gulp?)
                  How to run Gulp tasks sequentially one after the other(如何一個接一個地依次運行 Gulp 任務)
                  Visual Studio 2015 crashes when opening Javascript files(打開 Javascript 文件時 Visual Studio 2015 崩潰)
                  Detect FLASH plugin crashes(檢測 FLASH 插件崩潰)
                  • <bdo id='YbAPp'></bdo><ul id='YbAPp'></ul>
                        <tfoot id='YbAPp'></tfoot>
                        <i id='YbAPp'><tr id='YbAPp'><dt id='YbAPp'><q id='YbAPp'><span id='YbAPp'><b id='YbAPp'><form id='YbAPp'><ins id='YbAPp'></ins><ul id='YbAPp'></ul><sub id='YbAPp'></sub></form><legend id='YbAPp'></legend><bdo id='YbAPp'><pre id='YbAPp'><center id='YbAPp'></center></pre></bdo></b><th id='YbAPp'></th></span></q></dt></tr></i><div class="eh5bidv" id='YbAPp'><tfoot id='YbAPp'></tfoot><dl id='YbAPp'><fieldset id='YbAPp'></fieldset></dl></div>

                        <legend id='YbAPp'><style id='YbAPp'><dir id='YbAPp'><q id='YbAPp'></q></dir></style></legend>

                            <small id='YbAPp'></small><noframes id='YbAPp'>

                              <tbody id='YbAPp'></tbody>
                            主站蜘蛛池模板: 逗网红-抖音网红-快手网红-各大平台网红物品导航 | 温州富欧金属封头-不锈钢封头厂家 | 广东成考网-广东成人高考网| 武汉天安盾电子设备有限公司 - 安盾安检,武汉安检门,武汉安检机,武汉金属探测器,武汉测温安检门,武汉X光行李安检机,武汉防爆罐,武汉车底安全检查,武汉液体探测仪,武汉安检防爆设备 | 海德莱电力(HYDELEY)-无功补偿元器件生产厂家-二十年专业从事电力电容器 | 武汉高温老化房,恒温恒湿试验箱,冷热冲击试验箱-武汉安德信检测设备有限公司 | 耐磨陶瓷,耐磨陶瓷管道_厂家-淄博拓创陶瓷科技 | 拉伸膜,PE缠绕膜,打包带,封箱胶带,包装膜厂家-东莞宏展包装 | 上海办公室装修公司_办公室设计_直营办公装修-羚志悦装 | 福州时代广告制作装饰有限公司-福州广告公司广告牌制作,福州展厅文化墙广告设计, | 企业管理培训,企业培训公开课,企业内训课程,企业培训师 - 名课堂企业管理培训网 | 小程序开发公司-小程序制作-微信小程序开发-小程序定制-咏熠软件 | 厂房出租-厂房规划-食品技术-厂房设计-厂房装修-建筑施工-设备供应-设备求购-龙爪豆食品行业平台 | 微型实验室真空泵-无油干式真空泵-微型涡旋耐腐蚀压缩机-思科涡旋科技(杭州)有限公司 | 石油/泥浆/不锈钢防腐/砂泵/抽砂泵/砂砾泵/吸砂泵/压滤机泵 - 专业石油环保专用泵厂家 | 贵州科比特-防雷公司厂家提供贵州防雷工程,防雷检测,防雷接地,防雷设备价格,防雷产品报价服务-贵州防雷检测公司 | 管理会计网-PCMA初级管理会计,中级管理会计考试网站 | 检验科改造施工_DSA手术室净化_导管室装修_成都特殊科室建设厂家_医疗净化工程公司_四川华锐 | 派克防爆伺服电机品牌|国产防爆伺服电机|高低温伺服电机|杭州摩森机电科技有限公司 | 烘干设备-热泵烘干机_广东雄贵能源设备有限公司 | 蒸汽吸附分析仪-进口水分活度仪|康宝百科 | 艾乐贝拉细胞研究中心 | 国家组织工程种子细胞库华南分库 | 对夹式止回阀_对夹式蝶形止回阀_对夹式软密封止回阀_超薄型止回阀_不锈钢底阀-温州上炬阀门科技有限公司 | 湖南档案密集架,智能,物证,移动,价格-湖南档案密集架厂家 | 净化车间装修_合肥厂房无尘室设计_合肥工厂洁净工程装修公司-安徽盛世和居装饰 | WF2户外三防照明配电箱-BXD8050防爆防腐配电箱-浙江沃川防爆电气有限公司 | 防火卷帘门价格-聊城一维工贸特级防火卷帘门厂家▲ | 刘秘书_你身边专业的工作范文写作小秘书| 丙烷/液氧/液氮气化器,丙烷/液氧/液氮汽化器-无锡舍勒能源科技有限公司 | 钢板仓,大型钢板仓,钢板库,大型钢板库,粉煤灰钢板仓,螺旋钢板仓,螺旋卷板仓,骨料钢板仓 | 次氯酸钠厂家,涉水级次氯酸钠,三氯化铁生产厂家-淄博吉灿化工 | 隧道窑炉,隧道窑炉厂家-山东艾瑶国际贸易 | 广州/东莞小字符喷码机-热转印打码机-喷码机厂家-广州瑞润科技 | 绿叶|绿叶投资|健康产业_绿叶投资集团有限公司 | 精密钢管,冷拔精密无缝钢管,精密钢管厂,精密钢管制造厂家,精密钢管生产厂家,山东精密钢管厂家 | 电镀电源整流器_高频电解电源_单脉双脉冲电源 - 东阳市旭东电子科技 | 长沙中央空调维修,中央空调清洗维保,空气能热水工程,价格,公司就找维小保-湖南维小保环保科技有限公司 | 2025黄道吉日查询、吉时查询、老黄历查询平台- 黄道吉日查询网 | 预制围墙_工程预制围墙_天津市瑞通建筑材料有限公司 | 对照品_中药对照品_标准品_对照药材_「格利普」高纯中药标准品厂家-成都格利普生物科技有限公司 澳门精准正版免费大全,2025新澳门全年免费,新澳天天开奖免费资料大全最新,新澳2025今晚开奖资料,新澳马今天最快最新图库 | 合肥活动房_安徽活动板房_集成打包箱房厂家-安徽玉强钢结构集成房屋有限公司 |