javascript $find 在 IE 中返回 null
我正在使用 AJAX 控件工具包控件“TextBoxWaterMarkExtender”。问题最初是在 Firefox 中,使用 javascript 设置文本,如下所示:
var getDateField = document.getElementById('soandso');
getDateField.value = 'someandsome';
将在提交/发布时清除,因为 Extender 控件认为没有人编辑过它,因此它清除了“水印”。
它在 Firefox 中工作得很好,但 IE 在这一行上说“'null'是 null 或不是对象”:
var dateIdentified = $find("Beh" + sender).get_Text();
任何明显的事情我都在丢失的?
编辑:抱歉大家,我以为 $find 是一个 jQuery 函数。
编辑:更多代码:
function dateToday(sender)
{
var dateIdentified = $find("Beh" + sender).get_Text();
if (dateIdentified.length == 0)
{
var todaydate = new Date();
var smonth = todaydate.getMonth() + 1;
var sday = todaydate.getDate();
var syear = todaydate.getFullYear();
$find("Beh" + sender).set_Text(smonth.toString() + '/' + sday.toString() + '/' + syear.toString());
}
}
水印:
<toolkit:TextBoxWatermarkExtender BehaviorID="BehSTART_DATE" ID="WaterMarkSTART_DATE" runat="server"
TargetControlID="dcSTART_DATE"
WaterMarkText="mm/dd/yyyy" WaterMarkCssClass="searchHint" />
I'm using the AJAX Control Toolkit control "TextBoxWaterMarkExtender". The problem originally was that in Firefox, setting the text with javascript like so:
var getDateField = document.getElementById('soandso');
getDateField.value = 'someandsome';
Would be cleared on submit/post because the Extender control thought that nobody had edited it, so it was clearing the "watermark".
I followed this workaround: http://www.mindfiresolutions.com/Workaround-for-TextBoxWatermarkExtender-of-AjaxControlToolkit--855.php
and it works great in Firefox, but IE says "'null' is null or not an object" on this line:
var dateIdentified = $find("Beh" + sender).get_Text();
Anything obvious that I'm missing?
Edit: Sorry guys, I thought $find was a jQuery function.
Edit: More code:
function dateToday(sender)
{
var dateIdentified = $find("Beh" + sender).get_Text();
if (dateIdentified.length == 0)
{
var todaydate = new Date();
var smonth = todaydate.getMonth() + 1;
var sday = todaydate.getDate();
var syear = todaydate.getFullYear();
$find("Beh" + sender).set_Text(smonth.toString() + '/' + sday.toString() + '/' + syear.toString());
}
}
WaterMark:
<toolkit:TextBoxWatermarkExtender BehaviorID="BehSTART_DATE" ID="WaterMarkSTART_DATE" runat="server"
TargetControlID="dcSTART_DATE"
WaterMarkText="mm/dd/yyyy" WaterMarkCssClass="searchHint" />
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于任何有兴趣了解的人,我从使用 body onLoad 来调用我的 javascript 函数,
如本文建议的那样:http://blogs.telerik.com/dimodimov/posts/08-12-13/don_t_use_body_onload_in_asp_net_ajax_websites.aspx
现在 IE、Firefox 和 Chrome 都可以看到 $find 的值。
For anyone interested to know, I switched from using body onLoad to call my javascript function to
as this article suggested: http://blogs.telerik.com/dimodimov/posts/08-12-13/don_t_use_body_onload_in_asp_net_ajax_websites.aspx
Now IE, Firefox and Chrome all see a value for the $find.
尝试一下:
当您已经查找了一个或多个元素并且想要查找其中的子元素时,请使用 find() 。例如,您抓取一个表,然后想要查找表中具有 foo 类的所有元素,如下所示:
Try this:
find() is used when you've already looked up an element or elements and you want to find child elements inside of them. For example, you grab a table and then want to find all elements inside the table with a class of foo, like so: