php - 如何使用 mysql echo 覆盖 jquery 提示

标签 php jquery mysql

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

相关文章:

php - foreach,元素的意外结果,哪个键是 0

php - 悬停时在 php/mysql 中显示控件

javascript - 获取 JSON 文件的 AJAX 调用返回空值

php - 包括 Google map ,以便我可以通过管理中心动态更改位置

mysql - mysql从一个数据库插入到另一个数据库的语法错误

php - 将 Mustache.js 与 Mustache.php 结合使用

php - MySQL 查询按特定结果/行在另一个表中的投票数对结果进行排序

PHP 不从 ajax 调用输出 CSV

jquery - 可排序和可删除 : CSS preventing jquery-ui sortable to drag around the dropped items

mysql 存储过程 if else 与 select 不起作用