gpt4 book ai didi

javascript - 负载时 Chrome 值

转载 作者:行者123 更新时间:2023-12-03 21:52:11 26 4
gpt4 key购买 nike

我的 Chrome 浏览器在记住密码、用户名等时遇到一些问题。我无法检查输入字段是否为空。我使用以下代码,但 if 语句在 Chrome 中不起作用,但在所有其他浏览器中都有效。

$(document).ready(function() {    
$('.inputWithLabel').each(function(){
if ($(this).val().length != 0){
var element_id = $(this).attr('id');
$('label[for="' + element_id + '"]').addClass('inputWithText');
}
});
});

我尝试更改以下标签

<form action="" method="post">
<div class="divInputLabel inputLabel">
<label class="labelInput" for="username">Brugernavn*</label>
<input class="inputLabel inputWithLabel" id="username" name="username" type="text">
</div>
<div class="divInputLabel inputLabel">
<label class="labelInput" for="password">Adgangskode*</label>
<input class="inputLabel inputWithLabel" id="password" name="password" type="password">
</div>
<div class="divInputLabel inputLabel">
<label class="labelInput" for="password_again">Gentag adgangskode*</label>
<input class="inputLabel inputWithLabel" id="password_again" name="password_again" type="password">
</div>
<div class="divInputLabel inputLabel">
<label class="labelInput" for="first_name">Fornavn*</label>
<input class="inputLabel inputWithLabel" id="first_name" name="first_name" type="text">
</div>
<div class="divInputLabel inputLabel">
<label class="labelInput" for="last_name">Efternavn</label>
<input class="inputLabel inputWithLabel" id="last_name" name="last_name" type="text">
</div>
<div class="divInputLabel inputLabel">
<label class="labelInput" for="email">Email*</label>
<input class="inputLabel inputWithLabel" id="email" name="email" type="text">
</div>
<div class="divInputLabel inputLabel">
<input type="Submit" class="submit-button" value="Registre">
</div>
</form>

希望有人能帮助我。

最佳答案

尝试以下代码:

    $(document).ready(function() {
$('body .inputWithLabel').each(function(){
if ($(this).val().length != 0){
var element_id = $(this).attr('id');
$('label[for="' + element_id + '"]').addClass('inputWithText');
}
});
});

只需在每个循环中附加正文,即 $('body .inputWithLabel')

关于javascript - 负载时 Chrome 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25036333/

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