onselectedindexchanged()未被调用,确认框即使单击取消按钮也会清除文本

时间:2011-01-22 05:10:39

标签: c# javascript asp.net

当我从下拉列表中选择不同的项目时,我正在尝试清除RadEdiotors的内容。单击“确定”时,以下脚本会清除编辑器的内容,但在显示的“确认”框中单击“即时”按钮时,它也会清除内容。以下脚本有什么问题?也, 在后面的代码中,当列表中有一个不同的项目是selecetd时,也不会调用此下拉列表的onselectedindexchanged()事件。 我如何使其工作?请帮忙。谢谢。

<script type="text/javascript">

        var showConfirm = 1; 

   function onClientSelectedIndexChanging(item) {
    var editor1 = $find("<%= Editor1.ClientID %>");
    var editor2 = $find("<%= Editor2.ClientID %>");
    var content= editor.get_html();  
    var callBackFn = function (arg) 
    { 
        if (arg == true && showConfirm == 1) 
        { 
            var combo = item.ComboBox; 
            combo.ClearSelection(); 

            showConfirm = 0; 

            combo.FindItemByText(item.Text).Select(); 
            combo.SetText(item.Text); 

            __doPostBack("cboxLanguage", '{\"Command\":\"Select\"}'); 

            showConfirm = 1;             
        } 
    }


    if (showConfirm == 1 && content != '') 
    {

        confirm('Changing the language will clear the content of the ediotrs. Click OK to proceed.', callBackFn);

        alert(confirm);
         if (content != null) 

         {
                 editor1.set_html("");
                 editor2.set_html("");
                 return true
          }
          else 
          {
              return false;
          } 
    } 
    return false; 
} 
</script> 

我正在使用的Telerik的Radcombobox和RadEditor。

这是我的组合框: -

   <telerik:RadComboBox ID="cboxLanguage" TabIndex="2" runat="server" AutoPostBack="false" OnSelectedIndexChanged="cboxLanguage_OnSelectedIndexChanged" OnClientSelectedIndexChanging="onClientSelectedIndexChanging">
</telerik:RadComboBox> 

我想如果确认== true则清除编辑的内容,否则不然。如何获得此确认框的“真实”值?另外,如何调用OnSelectedIndexChanged()事件?

有人可以帮忙吗?我在这里做错了什么?

编辑 警报(确认);返回完整的功能代码。如何获取真/假值并根据它清除编辑器的内容?

1 个答案:

答案 0 :(得分:1)

尝试用以下内容替换您的确认声明:

 var c = confirm('Changing the language will clear the content of the ediotrs. Click OK to proceed.', callBackFn);

这样做会将confirm函数的结果赋给名为'c'的变量,并且可以将该变量用作布尔值。

此外,您可以alert(confirm);

代替alert(c);