如果该文本字段中有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