如何在 javascript 文件函数中找到 Radnotification id
How to find Radnotification id insidet the javascript file function
我在我的 porject 中使用了 radcontrols,我想限制 radTextbox 不应该允许特殊字符,所以我在我的 aspx 页面中使用脚本函数它工作正常,但我想在整个项目中使用它,所以我想维护一个 javascript 文件,我想使用该函数,所以帮助我如何将文本框 ID 和通知 ID 传递给函数。这是我的代码
.aspx
脚本文件
function valueChangedHandler(sender, eArgs) {alert("Done");
var pattern = /^[a-zA-Z0-9's]*$/;
var value = sender.get_value();
var matchArray = value.match(pattern);
if (matchArray == null) {
var notification = $find("<%=lblNotification.ClientID %>");
notification.set_text('Enter AlphaNumerics Only!');
notification.show();
sender.clear();
sender.focus();
exit();
}
}
通知代码
<telerik:RadNotification runat="server" BorderColor="Black" BorderStyle="Solid" BackColor="ActiveBorder" BorderWidth="4" EnableRoundedCorners="true" EnableShadow="true" ID="lblNotification" Position="BottomRight" ShowCloseButton="true" Opacity="90" Title="Result" VisibleTitlebar="False">
</telerik:RadNotification>
上面工作正常,但我没有收到通知消息,所以告诉我如何传递通知ID。
您根本无法在外部 JS 文件中使用服务器代码块。服务器仅在 aspx/ascx 文件中分析它们。您可以做的是在页面上声明一个函数,该函数具有将返回所需引用的通知:
function getNotification(){
return $find("<%=lblNotification.ClientID %>");
}
然后 JS 文件中的函数将调用此函数:
var notification = getNotification();
还有其他方法可以在外部文件中使用 ClientID,例如在页面的全局变量中创建数组,但如果您不想依赖硬编码 ID,它们将在页面中包含代码。好吧,您也可以从代码隐藏中注入脚本,但没有太大区别。
相关文章:
- 如何将HTML id分配给元素,以及如何将JavaScript应用于元素
- difference between '$(<%= DDL.ID %>) & $('
- 使用Javascript获取所选选项ID
- 根据id将json数组组合为一个json数组
- 是否有一个JS/jQuery函数可以获取某个类的每个元素的ID
- 对id以某个字符串开头的元素进行计数
- 如果元素's的ID以数字开头
- 通过id和class属性获取元素
- 根据选项卡内部的文本链接中的哈希ID动态选择jqueryUI选项卡
- 使用当前日期生成随机id
- Javascript-ID冲突的几率
- Href:当前DIV中的目标ID
- 无法获取属性'Id'使用Knockout.js的未定义或空引用API
- Javascript复选框函数:;缺少:在属性id之后"
- Twitter引导程序Typeahead-Id&标签
- 如何与特定ID交谈
- chart.series[id].remove()无法刷新高位图表/高位股票中其他系列的图例属性
- 如何在速度模板中获取LiferayPortlet实例id
- 谷歌地图可以't添加正确的标记ID
- 如何在 javascript 文件函数中找到 Radnotification id