I have tried/searched a lot but couldn't solve my problem. I guess it is quite easy and some one can give me a hint/link.
I want to transfer all numbers in square brackets [123] on my webpage to a variable like this: var all_sources_url = "123,123,123,123," and attach the variable to a link.
Webpage example:
<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>
Link example
<h1>Link</h1>
<p><a href="" target="_blank" id="all_sources">List of all cited literarure</a></p>
JS trial (if the variable would look like described above it would work, but constructing the variable does not work.)
<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>
Thank you very much for your help! To
<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>
Hope this helps!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.