我有一個滾動到錨功能:需要註冊代碼javascript函數後面再調用它
function scrollToAnchor(aid) {
var aTag = $("a[name='" + aid + "']");
if (aTag.length) {
$('html,body').animate({
scrollTop: aTag.offset().top - 100
}, 'slow');
aTag.closest('.subpanel').effect("highlight", 5000);
}
}
HTML
<a id="A2" class="gridLabel" name="Add Action Item">
<span id="MainContent_Label19" title="Add/Edit an action item.">Add/Edit Action Item</span>
</a>
我要調用服務器端事件執行某種行動。一旦行動完成,我需要調用這個scrollToAnchor
。我嘗試這樣做:
ScriptManager.RegisterClientScriptBlock(this, GetType(), "OpenActions", "$(function(){
function scrollToAnchor(aid) { var aTag = $('a[name=''' + aid + ''']');if (aTag.length)
{$('html,body').animate({ scrollTop: aTag.offset().top - 100 },
'slow');aTag.closest('.subpanel').effect('highlight', 5000);}} $('#tblAction').show();
scrollToAnchor('Add Action Item');});", true);
但是我得到的console
我' '
和" "
,可能是因爲錯誤。有人可以幫助我形成這個。
我也試過:
ScriptManager.RegisterClientScriptBlock(this, GetType(), "OpenActions", "$(function()
{function scrollToAnchor(aid) { var aTag = $('a[name=\"' + aid + '\"]' + ']');if
(aTag.length) {$('html,body').animate({ scrollTop: aTag.offset().top - 100 },
'slow');aTag.closest('.subpanel').effect('highlight', 5000);}} $('#tblAction').show();
scrollToAnchor('Add Action Item');});", true);
小心從你的控制檯分享錯誤? – Xotic750