按下回车键输入状态值,打开国家手风琴但我的要求输入状态值按下回车键后应该隐藏或关闭,请建议我任何一个。
<!--1 pannel starts-->
<div class="panel panel-default">
<div class="panel-heading row">
<div class="col-md-4">Country</div>
<div class="col-md-4" id="ccountry"><?php
if (isset($c_country)) {
echo $c_country;
}
?>
</div>
<a data-toggle="collapse" data-parent="#accordion" href="#collapse1">
<div class="profile-edit col-sm-4 col-xs-4 col-md-4 aj-textbone">
<?php if (empty($c_country[0]) || empty($c_country)): ?>
Add
<?php else: ?>
<i class="fa fa-pencil"></i> Edit
<?php endif; ?>
</div>
</a>
</div>
<div id="collapse1" class="panel-collapse collapse">
<div class="panel-body">
<div class="row">
<div class="col-md-7 col-md-offset-2 text-center">
<label class="col-md-4">Country</label>
<div class="col-md-8">
<input name="country" id="country" type ="text" class="form-control"
value="<?= (isset($c_country)) ? $c_country : null; ?>"/><br>
<input type="hidden" name="save_bcountry" id="save_bcountry" value="<?= (empty($c_country[0]) || empty($c_country)) ? 'Save' : 'Update'; ?>">
<?php if (empty($c_country[0]) || empty($c_country)): ?>
<button type="submit" class="btn btn-success aj-text-btnbone" data-target="#collapse1" data-toggle="collapse">Save</button>
<?php else: ?>
<button type="submit" class="btn btn-success aj-text-btnbone" data-target="#collapse1" data-toggle="collapse">Update</button>
<?php endif; ?>
<button type="button" data-target="#collapse1" data-toggle="collapse" class="btn btn-warning cancel-name">Cancel</button>
</div>
</div>
</div>
</div>
</div>
</div>
<!--1 pannel ends-->
<!--2 pannel starts-->
<div class="panel panel-default">
<div class="panel-heading row">
<div class="col-md-4">State</div>
<div class="col-md-4" id="cstate">
<?php
if (isset($c_state)) {
echo $c_state;
}
?>
</div>
<a data-toggle="collapse" data-parent="#accordion" href="#collapse2">
<div class="profile-edit col-sm-4 col-xs-4 col-md-4 aj-textbtwo">
<?php if (empty($c_state[0]) || empty($c_state)): ?>
Add
<?php else: ?>
<i class="fa fa-pencil"></i> Edit
<?php endif; ?>
</div>
</a>
</div>
<div id="collapse2" class="panel-collapse collapse">
<div class="panel-body">
<div class="row">
<div class="col-md-7 col-md-offset-2 text-center">
<label class="col-md-4">State</label>
<div class="col-md-8">
<input name="state" id="state" type ="text" class="form-control"
value="<?= (isset($c_state)) ? $c_state : null; ?>"/><br>
<input type="hidden" name="save_bstate" id="save_bstate" value="<?= (empty($c_state[0]) || empty($c_state)) ? 'Save' : 'Update'; ?>">
<?php if (empty($c_state[0]) || empty($c_state)): ?>
<button type="submit" class="btn btn-success aj-text-btnbtwo" data-target="#collapse2" data-toggle="collapse">Save</button>
<?php else: ?>
<button type="submit" class="btn btn-success aj-text-btnbtwo" data-target="#collapse2" data-toggle="collapse">Update</button>
<?php endif; ?>
<button type="button" data-target="#collapse2" data-toggle="collapse" class="btn btn-warning cancel-name">Cancel</button>
</div>
</div>
</div>
</div>
</div>
</div>
<!--2 pannel ends-->
答案 0 :(得分:0)
在脚本中添加以下内容
$('input').keydown(function(event){
if(event.keyCode == 13) {
event.preventDefault();
$(this).closest("div").find(".btn-success").trigger('click');
return false;
}
});
<强>解释强>
希望这对你有用。如果还有什么让我们知道......