<bdo id='llq8B'></bdo><ul id='llq8B'></ul>

      <legend id='llq8B'><style id='llq8B'><dir id='llq8B'><q id='llq8B'></q></dir></style></legend>
      <tfoot id='llq8B'></tfoot>

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

    1. <i id='llq8B'><tr id='llq8B'><dt id='llq8B'><q id='llq8B'><span id='llq8B'><b id='llq8B'><form id='llq8B'><ins id='llq8B'></ins><ul id='llq8B'></ul><sub id='llq8B'></sub></form><legend id='llq8B'></legend><bdo id='llq8B'><pre id='llq8B'><center id='llq8B'></center></pre></bdo></b><th id='llq8B'></th></span></q></dt></tr></i><div id='llq8B'><tfoot id='llq8B'></tfoot><dl id='llq8B'><fieldset id='llq8B'></fieldset></dl></div>

        解析正负整数的字符串,Javascript

        时间:2023-07-31

        <legend id='HNgrM'><style id='HNgrM'><dir id='HNgrM'><q id='HNgrM'></q></dir></style></legend>
          <tbody id='HNgrM'></tbody>

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

                <bdo id='HNgrM'></bdo><ul id='HNgrM'></ul>
                  <tfoot id='HNgrM'></tfoot>

                  <i id='HNgrM'><tr id='HNgrM'><dt id='HNgrM'><q id='HNgrM'><span id='HNgrM'><b id='HNgrM'><form id='HNgrM'><ins id='HNgrM'></ins><ul id='HNgrM'></ul><sub id='HNgrM'></sub></form><legend id='HNgrM'></legend><bdo id='HNgrM'><pre id='HNgrM'><center id='HNgrM'></center></pre></bdo></b><th id='HNgrM'></th></span></q></dt></tr></i><div id='HNgrM'><tfoot id='HNgrM'></tfoot><dl id='HNgrM'><fieldset id='HNgrM'></fieldset></dl></div>
                  本文介绍了解析正负整数的字符串,Javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  所以我正在研究一个用 d3 制作的标签云示例.

                  So I am working through a tag cloud example made in d3.

                  http://www.jasondavies.com/wordcloud/#http%3A%2F%2Fsearch.twitter.com%2Fsearch.json%3Frpp%3D100%26q%3D%7Bword%7D=cloud

                  并且我试图在每个单词悬停时将 Div 放置在它的顶部,并且基本上遇到了问题,因为我放置 div 的方式取决于 svg word 元素的 transform 属性.

                  and am trying to position a Div ontop of each word when it is hovered over, and am basically having a problem because the way I am placing the div is dependent on the transform attribute of the svg word element.

                  这个转换属性是一个我需要解析的字符串,但是这个字符串包含了我需要抓取的正值和负值.

                  This transform attribute is a string I need to parse, but the string includes both positive AND negative values that I need to grab.

                  tagCloudHover.style("top", function(){
                  
                         //parses the words attributes for its position, and gives that position to tagCloudHover
                         var str, matches, index, num;
                          str = thisWord.attr("transform");
                          matches = str.match(/d+/g);
                          for (index = 1; index < 2; ++index) {
                                  num = (parseInt(matches[index], 10));
                  
                          }
                  
                  
                  
                          if(num<0){
                              return -num+"px";
                          }else{
                              return num+"px";
                          }
                    });
                  

                  我的代码如上,最后一条语句什么都不做,但它能够从字符串中获取一个 Int.问题是它不会抓住负号.

                  My code is as above, where the last statement does nothing, but it is able to grab an Int from the string. The problem is that it won't grab the negative sign.

                  我不是最擅长解析,但我尝试了几个不同的 str.match 函数,但似乎没有任何效果.

                  I am not the best at parsing, but I have tried a couple different str.match functions and nothing seems to work.

                  任何 parseNinjas 有什么想法吗?任何事情都有帮助.艾萨克

                  Do any parseNinjas have any ideas? anything helps. Isaac

                  推荐答案

                  你的正则表达式应该是/-?d+/g,基本上是添加可选-"到模式.

                  Your regex should be /-?d+/g, basically adding "optional -" to the pattern.

                  这篇关于解析正负整数的字符串,Javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:HTML 首字母缩写词“span"是什么意思?代表? 下一篇:如何在 HTML 链接中使用 JavaScript 变量

                  相关文章

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

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

                  1. <legend id='wQzKn'><style id='wQzKn'><dir id='wQzKn'><q id='wQzKn'></q></dir></style></legend>

                      • <bdo id='wQzKn'></bdo><ul id='wQzKn'></ul>
                      <tfoot id='wQzKn'></tfoot>