我有一个ASP.NET MVC应用程序,其内容通过javascript/jquery/json从客户端加载到div中。加载的内容包含带有引用更新服务器端值的函数的标记,然后重定向到重新加载整个页面。如何在javascript中执行回调+更新div标记
我希望用'something'代替a-tags,仍然调用服务器端函数,然后只重新加载div。
这样做的“正确”方式是什么?
温柔 - 我是新来的JS ;-)
都欢迎评论,
安德斯,丹麦
这是据我走到这一步。 getResponseCell()返回一个填有标签的td标签。 我已经错位峡谷建议进入。点击()此外,但它只是调用onClickedEvent ...
代码示例:
onClickedEvent=function()
{
return false;
}
getResponseCell=function(label, action, eventId)
{
tmpSubSubCell=document.createElement("td");
link = document.createElement("A");
link.appendChild(document.createTextNode(label));
link.setAttribute("href", "/EventResponse/"+ action + "/" + eventId);
//link.setAttribute("href", "#divContentsEventList");
//link.setAttribute("onclick", "onClickedEvent(); return false;");
link.setAttribute("className", "eventResponseLink");
link.click(onClickedEvent());
// link=jQuery("<A>Kommer<A/>").attr("href", "/EventResponse/"+ action + "/" + eventId).addClass("eventResponseLink");
// link.appendTo(tmpSubSubCell);
tmpSubSubCell.appendChild(link);
return tmpSubSubCell;
}
这为我工作的解决方案看起来像这样的:
onClickedEvent=function(event, actionLink)
{
event.preventDefault();
$("eventListDisplay").load(actionLink);
refreshEventList();
return false;
}
getResponseCell=function(label, action, eventId)
{
tmpSubSubCell=document.createElement("td");
link = document.createElement("A");
link.setAttribute("id",action + eventId);
link.appendChild(document.createTextNode(label));
actionLink = "/EventResponse/"+ action + "/" + eventId;
link.setAttribute("href", actionLink);
className = "eventResponseLink"+ action + eventId;
link.setAttribute("className", className);
$('a.'+className).live('click', function (event)
{
onClickedEvent(event,$(this).attr('href'));
});
tmpSubSubCell.appendChild(link);
return tmpSubSubCell;
}
for a-tags you mean''tag!? – 2010-04-28 12:18:42
如果我添加下面的行(这是你的建议?)我仍然没有调用onClickedEvent函数(或者至少调试器不停止在函数的断点处)... link.setAttribute(“ onclick“,”onClickedEvent(); return false;“); – 2010-04-28 12:42:47
你有没有更多的例子,你得到的反应或只是一些更多的细节? – Matt 2010-04-28 12:43:04