【问题标题】:Enter keypress function in Form doesn't work在表单中输入按键功能不起作用
【发布时间】:2014-03-24 13:43:10
【问题描述】:

我做了这个表格来计算运费:

<div class="container-frete">
<div class="title-frete">
    Simulação de Entrega:<br>
   <div class="label-frete"> Digite seu CEP<br>  </div>
    <input id="cep" type="text"/>
    <input id="botao" type="button" class="button-frete" value="<?php echo $this->__('Calcular'); ?>"/>
</div>
<div id="content-frete">

</div>

但我不知道如何让 enter 按键起作用:

<script>

  Event.observe('botao', 'click', function(event) {
      new Ajax.Updater('content-frete', '/Freteproduto?cep='+$('cep').getValue()+'&productid=<?php echo $produto->getId();?>', { method: 'get' });

  });

</script>

【问题讨论】:

  • 检查这可能会有所帮助stackoverflow.com/questions/1231327/…
  • 你在使用prototype吗?如果是这样,您是否链接了脚本&lt;script src="http://ajax.googleapis.com/ajax/libs/prototype/1/prototype.js"&gt;
  • 是的,它在点击时链接了它的工作,但是当我按下回车键时我需要这个

标签: javascript keypress enter


【解决方案1】:

我在 jquery 中新建一个

    jQuery.noConflict(); // INSIDE INPUT "CEP" 
if (jQuery('input#cep').length) { 
    jQuery('input#cep').click(function(){ // GET KEYPRESS "E"
        jQuery(document).keypress(function(e) { 
            var keycode = (e.keyCode ? e.keyCode : e.which); // ENTER? 
            if(keycode == '13') { 
                new Ajax.Updater('content-frete', '/Freteproduto?cep='+$('cep').getValue()+'&productid=<?php echo $produto->getId();?>', { method: 'get' });
            } 
        }); 
    }); 
}

【讨论】:

    猜你喜欢
    • 2014-05-13
    • 1970-01-01
    • 2021-11-23
    • 1970-01-01
    • 2020-07-31
    • 1970-01-01
    • 2014-09-27
    • 2010-11-28
    • 1970-01-01
    相关资源
    最近更新 更多