douou1872 2016-12-29 14:42
浏览 22
已采纳

如何在搜索栏输入中用“ - ”更改空格

When I insert a text I want to change space with "-" in a search bar (from "Samsung S7 Edge" to "Samsung-S7-Edge"). Here is my code :

<!-- BEGIN: search -->
<div id="search">
   <form action="{INSTALLDIR}index.php" method="get" name="searchprod" id="prodsearch">
      <table cellpadding="0" cellspacing="0" border="0">
         <tr>
            <td><input name="ps" type="text" id="searchbox" value="Cauta produse...ex. samsung-s7-edge" onfocus="this.value=''; this.style.color='#333333';" />
               <input type="hidden" name="sv" value="1" />
            </td>
            <td><input type="submit" value="Cauta" class="searchButton" /></td>
         </tr>
      </table>
   </form>
</div>
<!-- END: search -->
  • 写回答

2条回答 默认 最新

  • dpj775835868 2016-12-30 10:34
    关注

    I created a jsfiddle - which should work.

    So what it is doing:

    If a person is triggering the keypress event and the character typed is a space (char 32) I prevent the event and instead get the current value of the field and add a dash -.

    What it is not doing:

    If someone is pasting text, there is no keypress event and therefore no replacing of the space character.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?