如何不把ctl00_无处不在的code使用JQuery,选择元素通过ID和ASP.NET [英] How to use JQuery, select element by ID and ASP.NET without putting ctl00_ everywhere in the code

查看:106
本文介绍了如何不把ctl00_无处不在的code使用JQuery,选择元素通过ID和ASP.NET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有code类似于以下约600多引用...

I have about 600+ references of code similar to the following...

$("#ctl00_ContentMainPane_eliteUser").html

和更改主模板,才发现所有的code打破了,由于控制层次变化。

And changed the master template, only to find all the code had broken, due to the control hierarchy changing.

所有的JavaScript包含在单独的文件,所以我不能用code像这样...

All javascript is included in separate files, so I cannot use code such as this...

$("#<%= eliteUser.clientID%>").html

我想有一个很好的解决方案来解决这个问题,所以,一旦固定后,我不必修改所有code,如果在未来的模板更改。

I want to have a good solution to fixing this issue so that after fixing it once, I don't have to modify all the code if the template changes in the future.

推荐答案

如何在你的母版页定义,如JavaScript函数:

How about defining a JavaScript function in your master page such as:

function getContainerId() {
    return "<%=ContentMainPane.ClientID %>";
}

然后在你的包含的JavaScript文件做这样的事情:

Then in your included JavaScript files do something like this:

$("#" + getContainerId() + "_eliteUser");

这篇关于如何不把ctl00_无处不在的code使用JQuery,选择元素通过ID和ASP.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆