[英]How to call jQuery function using web browsers control C#
我想通过Web浏览器控件从C#调用jQuery事件。
这是jQuery函数:
$("#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");
你能告诉我我哪里错了吗?
使用invoke可以只调用如下方法:
function change(){
}
不要放入文档就绪触发器。 方法必须位于可访问级别。
只需编写代码即可在change()中调用所需的方法并调用它。
如果使用invokescript,则应放入JS代码,而不是方法名。
dynamic tabclick = webBrowser1.Document.InvokeScript("eval", new[] {
"(function() {jQuery('.class').trigger('click');})()" });
我已经在c#中使用了它,并且有效。 我们可以在该函数中编写jquery编码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.