текстовый ввод водяного знака с использованием пользовательского bindingHandler

Я пытался создать пользовательский bindingHandler, который я мог бы использовать, чтобы задать поведение водяного знака для полей ввода текста.

Отwatermark я имею в виду: добавить значения по умолчанию в текстовые поля, которые удаляются в фокусе, и заменяются на размытие, если текстовое поле еще пусто

Мне удалось заставить это работать, как показано в этом jsfiddle:http://jsfiddle.net/rpallas/nvxuw/

У меня есть 3 вопроса об этом решении:

Is there any way to change it so that I only have to declare the watermark value once? Currently I have to put it on the place where I declare the binding and I also have to initialise the observable with the same value in the viewModel - as it will otherwise have no initial value. Is there a better way of getting to the underlying observable that the elements value is bound to. I'm currently grabbing it using the allBindingsAccessor, but this feels wrong to me. Originally I was just setting the value using jquery $(element).val('') but this also felt wrong. Which is best, or is there a better way? Does any one have or know of an existing solution to this this problem? Am I re-inventing the wheel?

Ответы на вопрос(2)

Ваш ответ на вопрос