简体   繁体   English

触发javascript不起作用

[英]trigger javascript doesnt work

I develop in ASP and I use jquery . 我在ASP中开发,并且使用jquery。

I am unable to use the trigger function on page load . 我无法在页面加载时使用触发功能。

My change function works but not when I call loading 我的更改功能有效,但在我调用loading时不起作用

$(function () {
    $(<%= C36.ClientID %>).trigger("change");
});

<%-- C36 --%>
$(<%= C36.ClientID %>).change(function () {
    if ($(<%= C36.ClientID %>).val())
        Maj_AlertCFE('NoDest', '0');
    else
        Maj_AlertCFE('NoDest', '1');        
})

ClientID returns the "id" attribute of the element as it is rendered on the client. ClientID返回在客户端上呈现的元素的“ id”属性。 So if that id is, for example "myid", your jQuery statement will render like this: 因此,如果该id是例如“ myid”,则您的jQuery语句将如下所示:

$(myid).trigger("change");

Unless you have a Javascript variable named myid this code will obviously fail. 除非您有一个名为myid的Javascript变量, myid此代码显然将失败。

What you really need is this: 您真正需要的是:

$("#myid").trigger("change");

So you need to add in the quotes and # character to your statements: 因此,您需要在语句中添加引号和#字符:

$("#<%= C36.ClientID %>").trigger("change");

If it is working as is you should be able to simply do: 如果它按原样工作,您应该可以简单地执行以下操作:

$(<%= C36.ClientID %>).change(function () {
    if ($(this).val())
        Maj_AlertCFE('NoDest', '0');
    else
        Maj_AlertCFE('NoDest', '1');
//trigger change now        
}).change();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM