外部js文件jquery函数似乎没有获取clientId

发布于 2024-08-28 20:01:13 字数 179 浏览 5 评论 0原文

我使用外部 javascript 文件并且我有这个,

function getdropdownvalue()
{
   alert($("#<%=DLState.ClientID%>"));
}

但它似乎没有得到我的下拉列表的 clientId...任何建议...

I use an externel javascript file and i have this,

function getdropdownvalue()
{
   alert($("#<%=DLState.ClientID%>"));
}

but it doesn't seem to get my dropdown's clientId... Any suggestion...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

泼猴你往哪里跑 2024-09-04 20:01:13

该下拉列表位于您的外部 JavaScript 文件中吗?如果它是外部 .js 文件,它不知道您可能在互联网上的其他地方有一个下拉列表。

您需要从引用 JavaScript 的页面传递 ClientID。

.js 文件:

function doStuff(selector) {
    // do something with $(selector)
}

或 jQuery 方式:

jQuery.fn.doStuff = function() {
    return $(this).each(function() {
        // do something with $(this)
    }
};

.aspx 文件(包含外部 JS 后):

<script type="text/javascript">
    doStuff("#<%=DLState.ClientID%>");
</script>

顺便说一下,如果您只想获取下拉列表的值, $("...").val( ) 工作得很好。

And is that dropdown in your external JavaScript file? If it's an external .js file, it has no idea about the fact that you may have a dropdown somewhere else on the internet.

You need to pass the ClientID in from the page where you reference the JavaScript.

.js file:

function doStuff(selector) {
    // do something with $(selector)
}

or the jQuery way:

jQuery.fn.doStuff = function() {
    return $(this).each(function() {
        // do something with $(this)
    }
};

.aspx file (after including your external JS):

<script type="text/javascript">
    doStuff("#<%=DLState.ClientID%>");
</script>

By the way, if you just want to get the value of the dropdown, $("...").val() works quite fine.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文