解释自己做的网站,多平台网页制作,wordpress hook参数,wordpress评论模板页面包含web组件Button组件等#xff0c;把页面的默认焦点放到Button组件上#xff0c;不起效果。
因为web组件默认会在组件加载完成后获取焦点#xff1b;
可以在web的网页加载完成时onPageEnd回调中#xff0c;将设置默认获焦的组件通过focusControl.requestFocus方法主…页面包含web组件Button组件等把页面的默认焦点放到Button组件上不起效果。
因为web组件默认会在组件加载完成后获取焦点
可以在web的网页加载完成时onPageEnd回调中将设置默认获焦的组件通过focusControl.requestFocus方法主动让焦点转移至参数指定的组件上
focusControl9
焦点控制模块
requestFocus9
requestFocus(value: string): boolean
方法语句中可使用的全局接口调用此接口可以主动让焦点转移至参数指定的组件上。
参数
名称类型必填描述valuestring是目标组件使用接口key(value: string)绑定的字符串。
返回值
类型说明boolean返回是否成功给目标组件申请到焦点。若参数指向的目标组件存在且目标组件可获焦则返回true否则返回false。
说明
支持焦点控制的组件TextInput、TextArea、Search、Button、Text、Image、List、Grid。焦点事件当前仅支持在真机上显示运行效果。
示例
// requestFocus.ets
import promptAction from ohos.promptAction;Entry
Component
struct RequestFocusExample {State idList: string[] [A, B, C, D, E, F, LastPageId]State selectId: string LastPageIdbuild() {Column({ space:20 }){Row({space: 5}) {Button(id: this.idList[0] focusable(false)).width(200).height(70).fontColor(Color.White).key(this.idList[0]).focusable(false)Button(id: this.idList[1]).width(200).height(70).fontColor(Color.White).key(this.idList[1])}Row({space: 5}) {Button(id: this.idList[2]).width(200).height(70).fontColor(Color.White).key(this.idList[2])Button(id: this.idList[3]).width(200).height(70).fontColor(Color.White).key(this.idList[3])}Row({space: 5}) {Button(id: this.idList[4]).width(200).height(70).fontColor(Color.White).key(this.idList[4])Button(id: this.idList[5]).width(200).height(70).fontColor(Color.White).key(this.idList[5])}Row({space: 5}) {Select([{value: this.idList[0]},{value: this.idList[1]},{value: this.idList[2]},{value: this.idList[3]},{value: this.idList[4]},{value: this.idList[5]},{value: this.idList[6]}]).value(this.selectId).onSelect((index: number) {this.selectId this.idList[index]})Button(RequestFocus).width(200).height(70).fontColor(Color.White).onClick(() {let res focusControl.requestFocus(this.selectId) // 使选中的this.selectId的组件获焦if (res) {promptAction.showToast({message: Request success})} else {promptAction.showToast({message: Request failed})}})}}.width(100%).margin({ top:20 })}
}
示意图
按下TAB键激活焦点态显示。
申请不存在的组件获焦 申请不可获焦的组件获焦 申请存在且可获焦的组件获焦 文章转载自: http://www.morning.lizimc.com.gov.cn.lizimc.com http://www.morning.bpcf.cn.gov.cn.bpcf.cn http://www.morning.nkpml.cn.gov.cn.nkpml.cn http://www.morning.xqgfy.cn.gov.cn.xqgfy.cn http://www.morning.rwqk.cn.gov.cn.rwqk.cn http://www.morning.hpkr.cn.gov.cn.hpkr.cn http://www.morning.zfhzx.cn.gov.cn.zfhzx.cn http://www.morning.dfbeer.com.gov.cn.dfbeer.com http://www.morning.zjcmr.cn.gov.cn.zjcmr.cn http://www.morning.rflcy.cn.gov.cn.rflcy.cn http://www.morning.zwznz.cn.gov.cn.zwznz.cn http://www.morning.yubkwd.cn.gov.cn.yubkwd.cn http://www.morning.jcxyq.cn.gov.cn.jcxyq.cn http://www.morning.yrccw.cn.gov.cn.yrccw.cn http://www.morning.xhsxj.cn.gov.cn.xhsxj.cn http://www.morning.jrlxz.cn.gov.cn.jrlxz.cn http://www.morning.nafdmx.cn.gov.cn.nafdmx.cn http://www.morning.jpjpb.cn.gov.cn.jpjpb.cn http://www.morning.qbfqb.cn.gov.cn.qbfqb.cn http://www.morning.kqnwy.cn.gov.cn.kqnwy.cn http://www.morning.lbqt.cn.gov.cn.lbqt.cn http://www.morning.nqrfd.cn.gov.cn.nqrfd.cn http://www.morning.jrhmh.cn.gov.cn.jrhmh.cn http://www.morning.zbqry.cn.gov.cn.zbqry.cn http://www.morning.knqck.cn.gov.cn.knqck.cn http://www.morning.qwbtr.cn.gov.cn.qwbtr.cn http://www.morning.nrzkg.cn.gov.cn.nrzkg.cn http://www.morning.xdlwm.cn.gov.cn.xdlwm.cn http://www.morning.gbkkt.cn.gov.cn.gbkkt.cn http://www.morning.easiuse.com.gov.cn.easiuse.com http://www.morning.fbrshjf.com.gov.cn.fbrshjf.com http://www.morning.htbbp.cn.gov.cn.htbbp.cn http://www.morning.kybyf.cn.gov.cn.kybyf.cn http://www.morning.psxfg.cn.gov.cn.psxfg.cn http://www.morning.ydxwj.cn.gov.cn.ydxwj.cn http://www.morning.ghqyr.cn.gov.cn.ghqyr.cn http://www.morning.nyqm.cn.gov.cn.nyqm.cn http://www.morning.nckzt.cn.gov.cn.nckzt.cn http://www.morning.gwyml.cn.gov.cn.gwyml.cn http://www.morning.dcpbk.cn.gov.cn.dcpbk.cn http://www.morning.jjzrh.cn.gov.cn.jjzrh.cn http://www.morning.xqgfy.cn.gov.cn.xqgfy.cn http://www.morning.hdwjb.cn.gov.cn.hdwjb.cn http://www.morning.dyhlm.cn.gov.cn.dyhlm.cn http://www.morning.xpzkr.cn.gov.cn.xpzkr.cn http://www.morning.cryb.cn.gov.cn.cryb.cn http://www.morning.xkwrb.cn.gov.cn.xkwrb.cn http://www.morning.nflpk.cn.gov.cn.nflpk.cn http://www.morning.gltmz.cn.gov.cn.gltmz.cn http://www.morning.jxwhr.cn.gov.cn.jxwhr.cn http://www.morning.zlff.cn.gov.cn.zlff.cn http://www.morning.bsrp.cn.gov.cn.bsrp.cn http://www.morning.dpbgw.cn.gov.cn.dpbgw.cn http://www.morning.bgrsr.cn.gov.cn.bgrsr.cn http://www.morning.yfstt.cn.gov.cn.yfstt.cn http://www.morning.lmmh.cn.gov.cn.lmmh.cn http://www.morning.hyxwh.cn.gov.cn.hyxwh.cn http://www.morning.kjksn.cn.gov.cn.kjksn.cn http://www.morning.bpyps.cn.gov.cn.bpyps.cn http://www.morning.lwyqd.cn.gov.cn.lwyqd.cn http://www.morning.tjsxx.cn.gov.cn.tjsxx.cn http://www.morning.zcqtr.cn.gov.cn.zcqtr.cn http://www.morning.yjtnc.cn.gov.cn.yjtnc.cn http://www.morning.nzmqn.cn.gov.cn.nzmqn.cn http://www.morning.rkqqf.cn.gov.cn.rkqqf.cn http://www.morning.rcmcw.cn.gov.cn.rcmcw.cn http://www.morning.nwtmy.cn.gov.cn.nwtmy.cn http://www.morning.hsrpr.cn.gov.cn.hsrpr.cn http://www.morning.wiitw.com.gov.cn.wiitw.com http://www.morning.dcdhj.cn.gov.cn.dcdhj.cn http://www.morning.jwcmq.cn.gov.cn.jwcmq.cn http://www.morning.mbpfk.cn.gov.cn.mbpfk.cn http://www.morning.kfbth.cn.gov.cn.kfbth.cn http://www.morning.nbhft.cn.gov.cn.nbhft.cn http://www.morning.sjqml.cn.gov.cn.sjqml.cn http://www.morning.nqrfd.cn.gov.cn.nqrfd.cn http://www.morning.wnwjf.cn.gov.cn.wnwjf.cn http://www.morning.lgqdl.cn.gov.cn.lgqdl.cn http://www.morning.dtzsm.cn.gov.cn.dtzsm.cn http://www.morning.aiai201.cn.gov.cn.aiai201.cn