gpt4 book ai didi

javascript - 这是 jquery/javascript 中正确的语法吗?

转载 作者:行者123 更新时间:2023-12-01 02:06:59 25 4
gpt4 key购买 nike

在下面的 jquery 中,在“点”之前应该有一个右括号“)”:

".test($ ..."?

(/^\s*$/.test($(this).val()))

$(document).ready(function () {
$('#userlogin').css('color', '#cccccc').val('LOGINNAME');

$('#userlogin').blur(function () {
if (/^\s*$/.test($(this).val())) {
$(this).val('LOGINNAME');
$(this).css('color', '#cccccc');
$(this).valid();
}
}).focus(function () {
if ($(this).val() === 'LOGINNAME') {
$(this).val('');
$(this).css('color', '#000000');
}
});

如果没有,为什么不呢?该代码对我来说看起来有点奇怪。

最佳答案

代码正确:

/^\s*$/  // create a regex
.test( // call the test method on it
$(this) // create a jquery object
.val() // call the val method on it
)

但是,该值可以被缓存:var val = $(this).val();。那么该行可能不会让您感到困惑:/yourregex/.test(val)

关于javascript - 这是 jquery/javascript 中正确的语法吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10655942/

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