开发者

javascript $find returns null in IE

开发者 https://www.devze.com 2023-03-05 06:00 出处:网络
I\'m using the AJAX Control Toolkit control \"TextBoxWaterMarkExtender\". The problem originally was that in Firefox, setting the text with javascript like so:

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 g开发者_如何学JAVAuys, 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" /> 


For anyone interested to know, I switched from using body onLoad to call my javascript function to

Sys.Application.add_load(MyFunction);

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.


Try this:

$("Beh" + sender).text();

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:

var myTable = $('#myTable');
// more code
myTable.find('.foo');
0

精彩评论

暂无评论...
验证码 换一张
取 消