【问题标题】:Is it possible to remove a behavior from an element that was added using $create?是否可以从使用 $create 添加的元素中删除行为?
【发布时间】:2011-05-06 19:54:45
【问题描述】:

我正在使用以下代码在使用 cloneNode 动态创建的文本框上创建日历控件。问题在于,在 IE 中,它似乎将行为两次添加到文本框中,导致它不起作用。有没有办法可以在添加之前删除此行为,即仅防止再次添加它?这在 Firefox 中完美运行。谢谢!

var rawDateControlID = ctrlPrefix + 'txtStartDate' + tblPatientMedicationsRowCount;
var $tstCalendar = $("#" + rawDateControlID);
$create(AjaxControlToolkit.CalendarBehavior, { "id": $tstCalendar.attr("id") + "cld" }, null, null, $get($tstCalendar.attr("id")));

【问题讨论】:

    标签: javascript asp.net asp.net-ajax ajaxcontroltoolkit


    【解决方案1】:

    这在某些情况下似乎有帮助:

    var $tstCalendar = $('#' + txtStartDateID);    
    if ($find($tstCalendar.attr("id") + "cld"))
    {
       $find($tstCalendar.attr("id") + "cld").dispose();
    }
    $create(AjaxControlToolkit.CalendarBehavior, { "id": $tstCalendar.attr("id") + "cld" }, null, null, $get($tstCalendar.attr("id")));
    

    只需检查行为是否存在,以及在创建新行为之前是否确实消除了它。

    【讨论】:

      猜你喜欢
      • 2010-10-02
      • 2017-11-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-25
      • 1970-01-01
      • 1970-01-01
      • 2019-06-09
      相关资源
      最近更新 更多