gpt4 book ai didi

jquery - IE 特定 - 当 jquery 设置为 ""时,闪烁的光标在文本类型的输入中消失

转载 作者:搜寻专家 更新时间:2023-10-31 22:50:48 27 4
gpt4 key购买 nike

所以我有一个文本类型的输入字段,它有一个默认值 (YYYY),当它获得焦点时,YYYY 消失:

//inside document.ready
....

$("#year").focus(function(){
if(yearVal === "YYYY") {
$("#year").val("");
}
});

jQuery.validator.addMethod("numericCheck", function(value, element) {
return this.optional(element) || /^[0-9]{4}$/.test(value);
}, "Please enter a valid year");

$("#theForm").validate({
//set the rules for the field names
rules: {
year: {
required: true,
minlength: 4,
numericCheck: true
}
},
messages: {
year: {
required: "Please enter the year",
minlength : "Please enter a valid 4 digit year",
numericCheck : "Please enter a valid year"
}
},
errorPlacement: function(error, element) {
if(element.siblings("div.errorMessage").length)
{
element.siblings("div.errorMessage").remove();
}

element.parent().append('<div class="errorMessage"></div>');
element.siblings("div.errorMessage").html(error.html());

element.parents("tr.inputRow").removeClass("goodInputRow");
element.parents("tr.inputRow").addClass("errorInputRow");
},
onkeyup: false,
onfocusout: false,
onclick: false,
submitHandler: function(form) {
$(form).find(":submit").attr("disabled", true);
form.submit(); }
});


....
//inside theForm

<input type="text" id="year" name="year" style="width: 40px;" maxlength="4" value="YYYY" />

文本消失了,光标应该在字段中闪烁。这在 FF 中效果很好,但在 IE8 中,光标不会闪烁(并且消失了)。焦点仍然在该字段上,一旦用户键入内容,光标就会返回,但在此之前,光标不在那里。

我正在使用 jquery 1.4.4 和 IE8。我已经能够单独重新创建它(即页面上没有其他任何东西在运行)

我试过 $("#year").focus() —— 没有骰子。我可以专注于其他领域并让它出现在那里,但我真的不想为了解决这个问题而不得不转移注意力。

问题:IE8清除YYYY后有没有办法让光标闪烁?

编辑:感谢您的回复 - 我已经修改以包含更多相关详细信息。

最佳答案

试试这个:

$('#year').focus(function () {
if ($(this).val() === "YYYY") {
$(this).val("");
$(this).select();
}
});

这对我来说在 IE8 中工作得很好:)

关于jquery - IE 特定 - 当 jquery 设置为 ""时,闪烁的光标在文本类型的输入中消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5736770/

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