我有一个下拉框来自“ silviomoreto.github.io/bootstrap-select。”, 在这里,我需要关注页面加载的下拉菜单,因为我不想单击该下拉菜单来设置焦点。一旦页面加载,则焦点应直接移至下拉菜单
我尝试了以下代码
<select class="form-control show-tick" data-live-search="true" name="lstClass" id="lstClass" >
<option>Class1</option>
<option>Class2</option>
<option>Class1</option>
</select>
<script>
document.form1.lstClass.focus();
</script>
答案 0 :(得分:2)
您可以为此使用autofocus
。此属性将焦点设置为页面加载时具有该属性的第一个元素:
<select autofocus>
<option> TEST</option>
</select>
答案 1 :(得分:1)
只需将let buttonLocation = UIButton(frame: CGRect(x: 0, y: 0, width: 200, height: 500))
buttonLocation.setImage(UIImage(named: "image"), for: .normal)
buttonLocation.backgroundColor = .gray
buttonLocation.layer.cornerRadius = buttonLocation.frame.width / 2
buttonLocation.imageView?.contentMode = .scaleAspectFill //Here........
添加到autofocus
标记
select
答案 2 :(得分:0)
您可以使用autofocus
和jquery
通过两种方式完成操作
$('select[name="lstClass"]').focus();
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<select class="form-control show-tick" data-live-search="true" name="lstClass" id="lstClass" >
<option>Class1</option>
<option>Class2</option>
<option>Class1</option>
</select>