开发者

External js file jquery function doesn't seem to get clientId

开发者 https://www.devze.com 2022-12-27 01:51 出处:网络
I use an externel javascript file and i have this, function getdropdownvalue() { alert($(\"#<%=DLState.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...


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消