我看到一堆类似的问题,但没有找到我需要的答案。我有这个功能:
function fnGetContent(keyword) {
var NewKeyword = keyword.tag;
var type = keyword.type;
$.ajax({
type: "POST", //GetEvents(iType As Integer, sSearch As String)
url: "Default.aspx/GetEvents",
data: "{'iType':'"+ type +"','sSearch' : '" + NewKeyword + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
var res = unescape(msg.d);
$("#divResults").html(res);
$('.accordian_body').hide();
$('.accordian_head').click(function () {
$(this).next().animate(
{ 'height': 'toggle' }, 'fast'
);
$('.plus', this).toggleClass('subtract');
$('#<%= tSearch.ClientID %>').val() = 'Search by event, team, artist or venue';
});
}
});
return false;
}
从这里调用它很好:
<a href="javascript:void(0)" onclick="fnGetContent({'type' : '2', 'tag' : 'concert'});">TEST TAG</a>
但我也希望在我的Document.Ready
上调用此函数,我希望它在页面加载时正确运行,然后每当我希望通过{{1}更新结果时我会调用它}。这不起作用,类似问题的其他答案是不调用已准备就绪的功能,我知道可以从多个位置调用相同的功能,包括Document.Ready
<a href>
答案 0 :(得分:4)
删除引号,以便将对象传递给函数而不是字符串:
function fnGetContent({'type' : '2' , 'tag' : ' ' });
答案 1 :(得分:1)
如果有其他人遇到这个,我想出来了,不写功能,没有引号
$(document).ready(function () {
fnGetContent({'type' : '1' , 'tag' : ' ' });
});