我有一个包含2个div标签的表单。一个div标签是打开默认值而另一个标签是hide。按插入键打开该div标签。我试过但没有得到正确的输出,
<form class="form-horizontal" role="form" id="default" method="post" action="<?php echo base_url('Controller_page/add_sales_others/'.$this->session->userdata('cus_id'));?>">
<div class="col-lg-8">
<div class="col-xs-14 col-md-10 col-sm-12 col-sm-offset-0 ">
<div style="width:100%; align:left; margin-bottom: 20px;">
<!--table class="table table-bordered"-->
<table class="table table-striped table-hover metable table-bordered" id="nm">
<tr border="#ccc" ;>
<th><input class='check_all' type='checkbox' onclick="select_all()" /></th>
<!--th>S.No</th-->
<th width="340px" ;>Item Name</th>
<th width="60px" ;>Quantity</th>
<th>Vat %</th>
<th>Rate</th>
<th>Total</th>
<!--th>Action</th-->
</tr>
<tr>
<td width="10px" ;><input type='checkbox' class='case' /></td> <!--td width = "20px";><span id='snum'>1.</span></td-->
<td>
<b><input class="form-control" type='text' id='itemname_1' name='itemname[]' autofocus /></b>
</td>
<td class="td_class" width="40px" ;>
<b><input class="form-control" type='text' id='quantity_no_1' name='quantity_no[]' /></b>
<input type='hidden' name='customer_id_1' id='customer_id_1' value='<?php echo $this->session->userdata('cus_id') ?>' class='form-control' />
<input class='form-control' type='hidden' id='supplier_id_1' name='supplier_id[]' />
<input type="hidden" id="dummy_itemnum" />
<input type="hidden" id="dummy_itemname" />
</td>
<td width="120px" ;><b><input class="form-control" type='text' disabled maxlength="200" id='vat_no_1' name='vat_no[]' value="" /></b></td>
<td width="120px" ;><b><input class="form-control" type='text' disabled maxlength="200" id='rate_no_1' name='rate_no[]' /></b> </td>
<td width="120px" ;><b><input class="form-control" type='text' disabled id='total_no_1' name='total_no[]' /></b> </td>
</tr>
</table>
</div>
</div>
</div>
</form>
脚本代码:
我附上了我试过的脚本代码,请检查并完成我的需求,
$("#sideform").hide();
jQuery(document).bind('keydown', 'Insert',function() {
$("#sideform").show();
$("#nm").hide();
return false;
});
当我按下插入键侧表格get show(打开)并且id = nm标签得到关闭。谢谢@
答案 0 :(得分:0)
这是你在找什么?
每个Key
都有一个唯一的代码,您可以询问是否正在按下该代码(请查看下面的jQuery
代码)。 Insert
代码为45
$("#sideform").hide();
jQuery(document).bind('keydown', function(e) {
if (e.keyCode == 45 || e.keyCode == 9) {
$("#sideform").show();
$("#nm").hide();
}
return false;
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form class="form-horizontal" role="form" id="default" method="post" action="<?php echo base_url('Controller_page/add_sales_others/'.$this->session->userdata('cus_id'));?>">
<div class="col-lg-8">
<div class="col-xs-14 col-md-10 col-sm-12 col-sm-offset-0 ">
<div style="width:100%; align:left; margin-bottom: 20px;">
<!--table class="table table-bordered"-->
<table class="table table-striped table-hover metable table-bordered" id="nm">
<tr border="#ccc" ;>
<th>
<input class='check_all' type='checkbox' onclick="select_all()" />
</th>
<!--th>S.No</th-->
<th width="340px" ;>Item Name</th>
<th width="60px" ;>Quantity</th>
<th>Vat %</th>
<th>Rate</th>
<th>Total</th>
<!--th>Action</th-->
</tr>
<tr>
<td width="10px" ;>
<input type='checkbox' class='case' />
</td>
<!--td width = "20px";><span id='snum'>1.</span></td-->
<td><b><input class="form-control" type='text' id='itemname_1' name='itemname[]' autofocus/></b>
</td>
<td class="td_class" width="40px" ;><b><input class="form-control" type='text' id='quantity_no_1' name='quantity_no[]'/></b>
<input type='hidden' name='customer_id_1' id='customer_id_1' value='' class='form-control' />
<input class='form-control' type='hidden' id='supplier_id_1' name='supplier_id[]' />
<input type="hidden" id="dummy_itemnum" />
<input type="hidden" id="dummy_itemname" />
</td>
<td width="120px" ;><b><input class="form-control" type='text' disabled maxlength="200" id='vat_no_1' name='vat_no[]' value=""/></b>
</td>
<td width="120px" ;><b><input class="form-control" type='text' disabled maxlength="200" id='rate_no_1' name='rate_no[]'/></b>
</td>
<td width="120px" ;><b><input class="form-control" type='text' disabled id='total_no_1' name='total_no[]'/></b>
</td>
</tr>
</table>
</div>
</div>
</div>
</form>
<form id="sideform">show if i hit Insert</form>
注意我找不到您的第二个form
,所以我创建了一个快速
注意2 我使用Tab keyCode
更新了代码(即9
)