如果该文本字段中有 mysql echo,我如何覆盖 jquery 提示。 目前我有一个 jquery 提示,但是当该字段在 mysql 中有一个值并且我回显它时,jquery 提示仍然存在。
php jquery 提示脚本
$(document).ready(function () {
//Shows the title in the text box, and removes it when modifying it
$('input[title]').each(function (i) {
$(this).val($(this).attr('title')).addClass('hint');
$(this).focus(function () {
if ($(this).val() == $(this).attr('title')) {
$(this).val('').removeClass('hint');
}
});
$(this).blur(function () {
if ($(this).val() == '') {
$(this).val($(this).attr('title')).addClass('hint');
}
});
});
//Clear input hints on form submit
$('form').submit(function () {
$('input.hint').val('');
return true;
});
});
表单文本字段
<input type="text" name="name" id="name" title="insert here" value=<?php echo $row3['name']?> />
最佳答案
替换$(this).val($(this).attr('title')).addClass('hint');
使用以下代码:
if(!$(this).val()) {
$(this).val($(this).attr('title')).addClass('hint');
}
但是,您确实应该考虑使用 placeholder
属性。要使其在旧版浏览器中工作,只需添加 https://github.com/mathiasbynens/jquery-placeholder 中的脚本即可。
关于php - 如何使用 mysql echo 覆盖 jquery 提示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9550752/