gpt4 book ai didi

javascript - 全局onBlur/onFocus

转载 作者:太空宇宙 更新时间:2023-11-04 00:33:38 25 4
gpt4 key购买 nike

与其他人一样,我们的网络应用程序中到处都有表单。

到目前为止,我们一直在大多数表单元素中使用以下(或一些变体):

class="formThingy"    
onFocus="document.theForm.theField.className='formThingySelected';"
onBlur="document.theForm.theField.className='formThingy';"

这很痛苦。有没有一种简单的方法可以使用 javascript/jQuery 或 CSS 获得相同的结果?

我知道在 css 中我们可以使用 :hover 之类的东西,但这并不能满足我们的需求。

我的猜测是,我们可以使用 jQuery 做一些事情,它使用类“FormThingy”查看所有内容,然后将其更改为 onFocus 并返回到 Blur,我只是不确定从哪里开始。

最佳答案

$('.formThingy').bind('focus blur', function() {
$(this).toggleClass('formThingy formThingySelected');
});

关于javascript - 全局onBlur/onFocus,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1507140/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com