模糊后重置水印

时间:2013-04-09 10:37:16

标签: jquery watermark

首先,在页面加载时,我按如下方式设置默认水印:

function AddWatermarksDataEntry() {
    initialWatermarks = new Array();
    initialWatermarks.push(new Array("P1_BIRTHDATE_MASK", "__/__/____"));
    initialWatermarks.push(new Array("P2_BIRTHDATE_MASK", "__/__/____"));
    initialWatermarks.push(new Array("P1_VALIDFROM_MASK", "~#SF_DD/MM/YYYY~"));
    initialWatermarks.push(new Array("P2_VALIDFROM_MASK", "~#SF_DD/MM/YYYY~"));
    initialWatermarks.push(new Array("P1_IDENTITYDOCUMENTNUMBER", " "));
    initialWatermarks.push(new Array("P2_IDENTITYDOCUMENTNUMBER", " ")); //***-*******-**
    initialWatermarks.push(new Array("P1_VAT", "~#SF_9OR10_DIGIT~"));
    initialWatermarks.push(new Array("P2_VAT", "~#SF_9OR10_DIGIT~"));
    Watermarker(initialWatermarks);
}

稍后,当我调整我的身份证类型的下拉值时 我做了以下事情:

if(newIdentityDocumentType == "1")
            {
                ChangeIdentityDocumentNumberField($('#'+ whichPerson +'_IDENTITYDOCUMENTNUMBER'), $('#'+ whichPerson +'_NATIONALITY'), watermarkIdentityDocumentNumberBelgian, foreignPersonWaterMark, 14, 14);
                $('#'+ whichPerson +'_IDENTITYDOCUMENTNUMBER').mask('999-9999999-99');
                $('.'+ whichPerson + '.identityDocumentNumber').text('e.g. 123-456789112-34');
            }

我检查用户是否选择了正确的身份证明文件类型。如果他或她做了,那么改变输入字段的属性,具体来说,我想要调整水印。

ChangeidentityDocumentField方法调用将改变水印的方法:

function ChangeIdentityDocumentNumberField(IdentityDocumentNumberField, NationalityField, WatermarkBelgian, WatermarkForeign, MaximumBelgian, MaximumForeign) {
    if (NationalityField.val() == "0") {
        //omitted code
        ChangeWatermark(IdentityDocumentNumberField, WatermarkBelgian);
    } else {
        //omitted code
        ChangeWatermark(IdentityDocumentNumberField, WatermarkForeign);
    }
}

function Watermarker(newWatermark) {
for (i = 0; i < newWatermark.length; i++) {
    $('#' + newWatermark[i][0]).Watermark(newWatermark[i][1]);

    $('#' + newWatermark[i][0]).blur(function (item, watermark) {
        return function () {
            //if ($('#' + item).val() == '') {
                $('#' + item).Watermark(watermark);

            //};
        };
    } (newWatermark[i][0], newWatermark[i][1]));
};

}

用这个方法来解决问题,当我在输入字段中并且我想要出去时,调用上面的函数,一切顺利,我看到添加了水印(当我调试时,但是,突然之间,当代码跳转到:

} (newWatermark[i][0], newWatermark[i][1]));

我的水印重置为默认值!?

1 个答案:

答案 0 :(得分:0)

我通过删除上面的代码并用占位符替换它来解决这个问题。但是我因此遇到了一个新问题: Change placeholder text with jquery also auto-update in IE