请有人帮助修改以下内容,以便在页面加载时触发,而不是在单击按钮时触发。
$(function () {
$('a[href="#search"]').on('click', function(event) {
$('#search').addClass('open');
$('#search > form > input[type="search"]').focus();
});
$('#search, #search button.close').on('click keyup', function(event) {
if (event.target == this || event.target.className == 'close' || event.keyCode == 27) {
$(this).removeClass('open');
}
});
});
答案 0 :(得分:0)
只需从click
事件中获取代码:
<script type="text/javascript">
$(function () {
$('#search').addClass('open');
$('#search > form > input[type="search"]').focus();
$('#search, #search button.close').on('click keyup', function(event) {
if (event.target == this || event.target.className == 'close' || event.keyCode == 27) {
$(this).removeClass('open');
}
});
});
</script>