美好的一天,我正在尝试向我的先行者添加一个事件。请先检查我的脚本
的JavaScript
$("#itemid").typeahead({
source: function(query, process) {
$.ajax({
async:true,
url: '<?=base_url();?>do_mutasi/ItemList/'+$("#tipenya").val()+'/'+ $("#itemid").val().replace(/ /g,"_"),
dataType: 'JSON',
success: function(data) {
process(data);
}
});
},
minLength: 3
});
PHP
public function ItemList($tipe="",$itemid=""){
extract(populateform());
$newitemid = str_replace("' '",'_',$itemid);
$hasil = $this->modelmodel->showdata("SELECT ItemCode,ItemName from Item
where status = 1
and (ItemCode like '%".$itemid."%' or ItemName like '%".$newitemid."%') and ItemType like '%".$tipe."%'
");
$data = array();
foreach ($hasil as $hsl)
{
$data[] = $hsl->ItemCode .' [ '. $hsl->ItemName . ' ] ' ;
}
echo json_encode($data);
}
和我的HTML
<div class="form-group">
<label class="col-sm-2 control-label">Tipe</label>
<div class="col-sm-10">
<select required size="1" class="form-control" id="tipenya">
<?php
if(isset($tipeitem->ItemType)){
if(rtrim(ltrim($tipeitem->ItemType)) == "MERCHANDISE"){
echo " <option value='MERCHANDISE'>MERCHANDISE</option>";
}else if(rtrim(ltrim($tipeitem->ItemType)) == "GENERAL"){
echo " <option value='GENERAL'>GENERAL</option>";
}
else{
echo "<option value='MERCHANDISE'>MERCHANDISE</option>
<option value='GENERAL'>GENERAL</option>";
}
}
else{
echo "<option value='MERCHANDISE'>MERCHANDISE</option>
<option value='GENERAL'>GENERAL</option>";
}
?>
</select>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">Kode Item</label>
<div class="col-sm-10">
<input required type="search" autocomplete="off" name="dest" id="itemid" class="form-control" placeholder="Search..." data-provide="typeahead" /> </div>
</div>
来自浏览器控制台的php结果的数据示例。
["F160048 [ FLT SHOES L27506 BLUE ] ","F160049 [ FLT SHOES L27506 GREEN ] ","F160050 [ FLT SHOES L27506
ORANGE ] "]
上面的脚本没有任何问题。我只是想添加enter
事件。我怎样才能实现这一目标?抱歉我的英文不好
我发现问题是我的问题是因为我的Js在下面。如果我按enter
$('body').on('keydown', 'input, select, textarea', function(e) {
var self = $(this)
, form = self.parents('form:eq(0)')
, focusable
, next
;
if (e.keyCode == 13) {
focusable = form.find('input,a,select,button,textarea').filter(':visible');
next = focusable.eq(focusable.index(this)+1);
if (next.length) {
next.focus();
} else {
form.submit();
}
return false;
}
});
我可以解决这个问题,而不删除我的上一个js