繁体   English   中英

将方括号中的所有数字放入数组

[英]Push all numbers in square brackets into array

我已经尝试/搜索了很多,但无法解决我的问题。 我想这很容易,有人可以给我一个提示/链接。

我想将网页上方括号[123]中的所有数字传送到这样的变量:var all_sources_url =“ 123,123,123,123”,并将该变量附加到链接。

网页示例:

<h1>Text</h1>
<p>For a generative propagation, seeds must be harvested in winter from high quality sites in the nearby area or a site with similar growing conditions [682, 683].</p>
<p>Germination is increased by frost. Germination rates about 80 % can be achieved with good seeds [684].</p>

链接示例

<h1>Link</h1>
<p><a href="" target="_blank" id="all_sources">List of all cited literarure</a></p>

JS试用版(如果变量看起来像上面描述的那样,它将起作用,但是构造变量将不起作用。)

 <script type="text/javascript">
  $(document).ready(function() {
   var all_sources_url;       
   $.each(($("p").html().match(/\[(.+?)\]/g)), function( index, value){
    all_sources_url += value;
   });
  $("#all_sources").attr("href", "quellen.php?id=" + all_sources_url + "&name=literature");
 });
 </script>

非常感谢您的帮助!

 <script type="text/javascript">
  $(document).ready(function() {
   var all_sources_url = [];       
   $.each(($("p").html().match(/\[(.+?)\]/g)), function( index, value){
    all_sources_url.push(value.replace("[", "").replace("]", ""));
   });
  $("#all_sources").attr("href", "quellen.php?id=" + all_sources_url.join(",") + "&name=literature");
 });
 </script>

希望这可以帮助!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM