简体   繁体   中英

How to call jQuery function using web browsers control C#

I want to call a jQuery event from C# via web browser control.

Here's the jQuery function:

$("#veh-brand").change(function() {
    var brand = $(this).val();
    var dataString = "brand=" + brand;
    $text = $("#veh-brand [value='" + brand + "']").text();
    $('#full-car').html($text);
    $.ajax({
        type: "POST",
        url: "/external/ws-brand_year.php",
        data: dataString,
        cache: false,
        dataType: 'JSON',
        success: function(response) {
            var html = "<option value=''>Escoger</option>";
            for (var i = 0; i < response.length; i++) {
                html += "<option class='contrast' value=" + response[i].id + ">" + response[i].description + "</option>"
            }
            $("#veh-brand-year").html(html);
        }
    });
});

this.webBrowser1.Document.InvokeScript("change");

Can you tell me where I am wrong?

Using invoke you can call just methods like this:

function change(){
}

Don't put in document ready trigger. Method must be located on accessible level.

Just write code which will call needed method in change() and call it.

If you use invokescript you should put inside JS code, not method name.

  dynamic tabclick = webBrowser1.Document.InvokeScript("eval", new[] { 
    "(function() {jQuery('.class').trigger('click');})()" });

I have used this in c# and it worked . we can write the jquery coding in that function.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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