我正在尝试
通过使用事件 ( ) 为该“TBXinsertDate”asp:TextBox
控件设置默认值,但是……在我看来,如果这是问题所在,
实际上它会用它自己的操作覆盖我的操作,focus
js
ajax watermark Extender
我如何设置自己的默认值?
aspx
<cc1:TextBoxWatermarkExtender ID="insertDate_TextBoxWatermarkExtender" runat="server" TargetControlID="TBXinsertDate" WatermarkText="insertDate" WatermarkCssClass="WaterMarkedTextBox">
</cc1:TextBoxWatermarkExtender>
<cc1:MaskedEditExtender enabled="true" MaskType="Date" ID="insertDate_MaskedEditExtender" runat="server" BehaviorID="tet"
TargetControlID="TBXinsertDate" InputDirection="LeftToRight" CultureName="en-GB"
UserDateFormat="None" Mask="99/99/9999" MessageValidatorTip="true" OnFocusCssClass="maskedFocus" ErrorTooltipEnabled="true" ErrorTooltipCssClass="toolTipForInvalid">
</cc1:MaskedEditExtender>
<asp:TextBox ID="TBXinsertDate" runat="server" ToolTip="please insert date" Width="76px">
</asp:TextBox>
我知道,我可以使用任何类型的 datePicker ...,但要求是有问题的,通过键盘手动设置。
更新
默认应该是今天的日期,比如...26/12/2012
更新 #2代码
下面是:Javascript+Ajax双模水印
Update3和最重要的一个:
1)不是这个Js代码是我的问题的特殊之处......它甚至不是它的来源
2) 如果我从 ASPX 中省略 Ajax Extenders: validation
+ ,则问题不存在!maskEdit
3)总结一下,问题是设置默认值=今天日期
如果我不添加扩展器 - validator
+Maskedit
我的尝试工作正常!值已设置。
请有经验的人在Ajax Toolkit
这里提供一些帮助。
我也会更新这个问题的标题
var masked = "__/__/____";
var MultiWatermark = function (obj, options) {
var defaultOptions = {
// These variables can be changed to alter functionality using the passed in options object
watermarkVals: ["insert date", "mmddyyyy"], // all watermark values.
totalIterations: 20, // how many times to go through watermark Array.
watermarkClassName: "WaterMarkedTextBox",
normalClassName: "NormalTextBox",
changeDelay: 1000, // in milliseconds
extraValsToCheck: ['', null]//
}
//merge options with defaultOptions
for (var property in defaultOptions) {
if (!options.hasOwnProperty(property)) {
options[property] = defaultOptions[property];
}
}
// local variables (do not change)
var textBox = obj;
var iterationCounter = 0;
var itemCounter = 0;
var intrId;
var startWatermark = function () {
itemCounter = 0; iterationCounter = 0; // resets for after blur
intrId = setInterval(function () { alterWaterMark() }, options.changeDelay);
}
var stopWatermark = function () {
clearInterval(intrId);
}
var alterWaterMark = function () {
if (iterationCounter < options.totalIterations) {
textBox.value = options.watermarkVals[itemCounter];
itemCounter += 1;
if (itemCounter == options.watermarkVals.length) {
itemCounter = 0;
iterationCounter += 1;
}
}
else {
stopWatermark();
}
}
var isWatermarkValue = function (val) {
var i = options.watermarkVals.length;
while (i--) {
if (options.watermarkVals[i] === val) {
return true;
}
}
// value is not in watermark array, so check secondary values.
i = options.extraValsToCheck.length;
while (i--) {
if (options.extraValsToCheck[i] === val) {
return true;
}
}
}
var setClass = function () {
textBox.className = isWatermarkValue(textBox.value) ? options.watermarkClassName : options.normalClassName;
///////this is wher i tried to set it <==========
textBox.value = "26/12/2012";
}
var focusEvent = function () {
stopWatermark();
if (isWatermarkValue(textBox.value)) {
textBox.value = "";
///////this is where i was First time trying to set it <==========
//alert("was focused");
}
setClass()
}
var blurEvent = function () {
if (isWatermarkValue(textBox.value)) {
startWatermark();
}
setClass();
}
var initWatermark = function () {
setClass();
textBox.onfocus = focusEvent;
textBox.onblur = blurEvent;
startWatermark();
}
initWatermark();
}
function runWatermarkOn(formId, targetid, wm1,wm2,wm3, iterations, delay) {
var dateOptions = {
// These variables alter functionality, the main script will use the defaults of any options not included here
watermarkVals: [wm1, wm2], // all watermark values.
totalIterations: iterations,
changeDelay: delay, // in milliseconds
extraValsToCheck: ['', null, masked]
}
if (wm3!= undefined)
dateOptions.watermarkVals[2] = arguments[4];
new MultiWatermark(document.forms[formId].elements[targetid], dateOptions);
}
runWatermarkOn("form1", "TBXinsertDate", "insert Date", "dd/mm/yyyy", undefined, 2, 1500);
请参阅上面代码块中间的注释。那就是我尝试的地方。尝试硬编码今天的日期,因为它的价值。正如我所指的问题。这个想法是,我尝试使用什么 javascript 或 Jquery 并不重要,因为 MaskEditExtender 超过了我的价值。
我将非常感谢这里的一些帮助。
谢谢