2013-08-23 41 views
0

我想禁用在Joomla模块内的窗体中的输入按键,但我无法得到它的工作......这是代码有。禁用输入表格

<script type="text/javascript"> 
    function stopRKey(evt) { 
     var evt = (evt) ? evt : ((event) ? event : null); 
     var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null); 
     if ((evt.keyCode == 13) && (node.type=="text")) {return false;} 
    } 

    document.onkeypress = stopRKey; 
</script> 

<form id="searchbox" action="<?php echo JRoute::_('index.php'); ?>"       method="post"   role="search"> 
    <input type="text" value="" name="searchword" placeholder="<?php echo JText::_('TPL_WARP_SEARCH'); ?>" /> 
    <button type="reset" value="Reset"></button> 
    <input type="hidden" name="task" value="search" /> 
    <input type="hidden" name="option" value="com_search" /> 
    <input type="hidden" name="Itemid" value="<?php echo $itemid > 0 ? $itemid : JRequest::getInt('Itemid'); ?>" /> 
</form> 

<script src="<?php echo $warp['path']-> url('js:search.js'); ?>"></script> 

<script> 
    jQuery(function($) { 
     $('#searchbox input[name=searchword]').search({'url': '<?php echo  JRoute::_("index.php?option=com_search&tmpl=raw&type=json&ordering=& searchphrase=all");?>', 'param': 'searchword', 'msgResultsHeader': '<?php echo JText::_("TPL_WARP_SEARCH_RESULTS"); ?>', 'msgMoreResults': '<?php echo JText::_("TPL_WARP_SEARCH_MORE"); ?>', 'msgNoResults': '<?php echo JText::_("TPL_WARP_SEARCH_NO_RESULTS"); ?>'}).placeholder(); 
    }); 
</script> 

我尝试了不同的剧本,但至今没有运气...

+0

什么是错的,你得到一个错误?什么都没有发生?有什么事情发生,但不是你想要的? – SmokeyPHP

+1

也许这将有助于:http://stackoverflow.com/questions/895171/prevent-users-from-submitting-form-b​​y-hitting-enter。 –

回答

0
("input").live("keypress", function(e) { 
     if (e.keyCode == 13) { 
      event.preventDefault(); 
      return false; // prevent the button click from happening event.preventDefault() or return false, either one is enough 
     } 
}); 
+0

看看我的网站... http://www.kennymassai.com/gamepedia。如果你搜索蝙蝠侠,你会在弹出框中得到一些结果,但是当你按下回车键时会打开一个搜索页面。这是我想要防止的。所以只是在弹出框中的结果,没有别的... –

0

变化这在HTML搜索按钮:

<input type="text" class="searchButton" value="" name="searchword" placeholder="<?php echo JText::_('TPL_WARP_SEARCH'); ?>" /> 

然后在脚本:

$(".searchButton").click(e){ 
    if (e.keyCode == 13) { 
     return false; // prevent the button click from happening 
     e.preventDefault(); // prevent default html form submit 
    } 
} 
+0

感谢罗伊,但形式不响应了...你可以在这里看到我的网址...右上... http://www.kennymassai。 COM/gamepedia/index.php文件/任天堂的Wii-U –