我正在尝试启动一个回发,调用服务器运行元素的单击函数,以便在某个特定的C#对话框按钮单击时运行一些jquery代码。
根据this jQuery UI示例,我使用带有按钮的模式对话框。我已经尝试在this问题中使用javascript/jquery回发调用的所有不同答案。
我在我的C#代码中设置了几个断点,以查看是否调用了这些回发,但没有任何回发被调用。
我在我的ascx文件中使用了这个虚拟元素:
<a id="anchorId" runat="server" onclick="return true;" onserverclick="TryLogin"></a>
我尝试了几种不同的方式来实现这个回发:
$("#anchorId").click(); //just simply does nothing
document.getElementById("anchorId").click(); //This one gives me a null javascript error
$("document").getElementById("#anchorId").click(); //tells me [object] doesn't have a getElementById
__doPostBack('<%=anchorId.UniqueID %>', '');//Also does nothing in the jQuery code, but works in standard javascript code
最后,我尝试在代码后面检索唯一ID,如下所示:
string id = anchorId.UniqueID;
并在javascript中以这种方式替换:
__doPostBack('Softening_Main$anchorId', '');//Still does nothing, and no javascript error
我真的需要一些帮助,有什么想法吗?
发布于 2012-02-16 02:56:18
你的代码中有几个问题。
$("document")
不会选择document
,而是在页面上查找document
标记元素。您应该使用$(document)
删除引号。
此外,getElementById
是document
对象的JavaScript方法,用于根据id查找元素。在使用getElementById
时,不要在id中指定#
。jQuyer使用#
来区分不同的选择器。
从锚点移除内联onclick="return true;"
并尝试此操作。
$("#anchorId").click(function(e){
__doPostBack('<%=anchorId.UniqueID %>', '');
return false;
});
https://stackoverflow.com/questions/9299265
复制相似问题