我有一个 JQuery (v1.8),它在单击超链接后处理代码。我想调用该单击或执行任何其他操作(就像单击链接一样)以强制 JQuery 从后面的代码运行。有什么想法吗?
JQuery 代码:
<script type="text/javascript">
jQuery(document).ready(function (){
jQuery('#lnkShowModule').toggle(
function (){
jQuery(this).html('Hide the Module');
jQuery('.hide-element').toggle();
},
function (){
jQuery(this).html('Show the Hidden Module');
jQuery('.hide-element').toggle();
}
);
});
这是我在 ascx 控件中的链接:
<a id="lnkShowModule" href="#"> show the hidden module</a>
有什么想法吗?
最佳答案
在一个函数中添加javascript代码,你可以在任何你想调用javascript函数的地方添加下面的代码
Page.ClientScript.RegisterStartupScript(Page.GetType(), "ShowHide", "ShowHideDiv();", true);
#UPDATE 1
function ShowHideDiv(){
$(document).ready(function (){
$('#lnkShowModule').toggle(
function (){
$(this).html('Hide the Module');
$('.hide-element').toggle();
},
function (){
$(this).html('Show the Hidden Module');
$('.hide-element').toggle();
}
);
});
}
你还必须改变“a”
<a id="lnkShowModule" href="#" onclick="ShowHideDiv();"> show the hidden module</a>
关于javascript - 从 VB.NET 背后的代码调用点击事件或 JQuery 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18422120/