如何将某些部分更改为小写且没有空格?

问题描述 投票:0回答:1

我到此为止已经可以在页面上打印出我想要的信息了(这仅供我个人使用),作为生成器来为我加快速度。但是我想得到一部分以删除表单条目之间的任何空格,并将其更改为小写。例如,当它显示去年的#Korn采访时我希望它改为显示#korninterviewlastyear但仅在生成主题标签的那一部分

非常感谢您提供任何帮助。非常感谢。

其他一切都很好,我想完成的事情

<font face="Verdana, Arial, Helvetica, sans-serif">
<style>
#entries,#results{float:left}
</style>
</font>
<div id="entries"> 
  <form name ="myform">
    <p><font face="Verdana, Arial, Helvetica, sans-serif">Band: 
      <input type="text" name="band"/>
      <br>
      Song: 
      <input type="text" name="song"/>
      <br>
      Title: 
      <input type="text" name="title"/>
      <br>
      YT Link: 
      <input type="text" name="link"/>
      <br>
      <input type="hidden" name="disc" value="*Copyright Disclaimer Under Section 107 of the Copyright Act of 1976, allowance is made for 'fair use' for purposes such as criticism, comment, news reporting, teaching, scholarship, and research. Fair use is a use permitted by copyright statute that might otherwise be infringing. Non-profit, educational or personal use tips the balance in favor of fair use. No copyright infringement intended. ALL RIGHTS BELONG TO THEIR RESPECTIVE OWNERS*"/>
      <br>
      <input type="hidden" name="comma" value=","/>
      <br>
      <input type="button" value="display" onclick="collect(this.form)"/>
      </font></p>
    <p>&nbsp;</p>
    <p><font face="Verdana, Arial, Helvetica, sans-serif">__________________ </font></p>
  </form>
</div>
<div id="results"></div>
<p> <font face="Verdana, Arial, Helvetica, sans-serif">
  <script type="text/javascript">
function collect(frm) { 
document.getElementById("results").innerHTML+=" #"+frm.band.value+" #"+frm.song.value+" #reaction<br><br>Thanks for the subs and views. Lets hit a Million this year!<br><br>Link If You Would Like To Contribute: http://www.peredyrock.com/reactions<br><br>Link to original video: "+frm.link.value+"<br><br>Click Here To Subscribe! https://www.youtube.com/peredymusic<br><br>All of my videos: https://www.youtube.com/peredymusic<br><br>Peredy Channel Merch: https://shop.spreadshirt.com/peredyytmerch<br><br><br><br>"+frm.disc.value+"<br><br><br><br>#"+frm.band.value+" #"+frm.band.value+"once #"+frm.song.value+" #"+frm.song.value+"video #musicvideo #live #official #video #metalheadreaction #youtube #peredyreactions #peredy #firsttime #once #rock #pop #goth #metal #metalhead #music #reaction #metalreaction #youtube #peredyreacts<br><br><br><br><br><br><br><br>"+frm.band.value+""+frm.comma.value+""+frm.song.value+""+frm.comma.value+""+frm.title.value+""+frm.comma.value+""+frm.title.value+" "+frm.band.value+" reaction"+frm.comma.value+""+frm.band.value+" "+frm.song.value+""+frm.comma.value+""+frm.band.value+" "+frm.song.value+" official"+frm.comma.value+""+frm.band.value+" "+frm.song.value+" reaction"+frm.comma.value+""+frm.song.value+" reaction"+frm.comma.value+""+frm.band.value+" "+frm.song.value+" live reaction"+frm.comma.value+""+frm.song.value+" live reaction"+frm.comma.value+""+frm.band.value+" live reaction"+frm.comma.value+""+frm.band.value+" "+frm.song.value+" official"+frm.comma.value+""+frm.band.value+" "+frm.song.value+" live"+frm.comma.value+"official live reaction"+frm.comma.value+"gothic metal reaction"+frm.comma.value+"goth metal reaction"+frm.comma.value+"rock reaction"+frm.comma.value+"peredy"+frm.comma.value+"metal reaction"+frm.comma.value+"metal head reaction"+frm.comma.value+"peredy reacts"+frm.comma.value+"<hr>"
frm.reset();
} 
</script>
  </font></p>
<p>&nbsp;</p>
javascript html forms spaces lowercase
1个回答
-1
投票

这就是我的做法:

function collect(frm) { 
  document.getElementById("results").innerHTML += "#" + [frm.band.value, frm.song.value].join('').toLowerCase() /* + whatever else you need here... */;
}

您可能还希望摆脱标点符号,因此可以使用String.prototype.replace()函数将任何模式替换为您喜欢的字符串。

另外,我建议使用较新的字符串插值语法切换为连接字符串:

`#${[frm.band.value, frm.song.value].join('').toLowerCase()}`
© www.soinside.com 2019 - 2024. All rights reserved.