在jquery UI中,您现在可以将.button()
应用于锚、按钮、提交按钮等。我有一个简单的asp.net按钮,如下所示:
<asp:Button ID="btnFindSearch" runat="server" Text="Search"
onclick="btnFindSearch_Click" />
然而,它位于updatepanel中,如下所示:
<div id="dialog" title="Select Address">
<asp:UpdatePanel ID="upNewUpdatePanel" UpdateMode="Conditional" ChildrenAsTriggers="true" runat="server">
<ContentTemplate>
<div id="search" style="width:100%; text-align:center;">
<asp:TextBox ID="txtFindSearch" runat="server"></asp:TextBox>
<asp:Button ID="btnFindSearch" runat="server" Text="Search"
onclick="btnFindSearch_Click" />
</div>
</ContentTemplate>
</asp:UpdatePanel>
</div>
在我的jquery中,我可以做到:
$('#btnFindSearch').button();
它给了我jquery ui的外观,我想是一个button...awesome。但是,当我单击我的按钮时,该按钮返回到看起来很普通的asp.net服务器按钮。这就好像不再应用.button()
一样。
这是因为它在UpdatePanel中,还是什么原因造成的?
发布于 2012-04-23 06:53:31
这可以使用jQuery plugin来完成。
它可用于为dom中当前存在的所有元素以及稍后将添加的元素定义函数。这将会解决你的大部分问题。
下面是一个用法示例:
$("#btnFindSearch").livequery(function(){$(this).button();})
发布于 2012-04-23 06:29:59
这是因为单击按钮时会出现服务器PostBack,并替换原始的DOM元素。
UpdatePanel并不是特别聪明。它只是将所有的子内容替换为从服务器发送的新的超文本标记语言(想想innerHTML = severStuff
)。因此,新创建的DOM元素是“未修饰的”。需要在新的DOM元素上再次运行.button()
魔术。
除非有更好的方法来处理这个问题(我不知道有什么更好的方法),否则这里有一个可以自动处理不同场景的helpful class for inline script blocks。这是一种杂乱和"hackish",但它确实工作得很好(我们使用一个修改过的版本)。
用法可能如下所示(这必须是inside更新后的UpdatePanel,以便在部分PostBacks上工作):
<UpdatePanel ...>
<OtherControls ...>
// Put other controls first, because this will be rendered in-order
// (which should usually be last!) in a normal/full PostBack.
// It will use the appropriate "RegisterScript" for partial PostBacks.
<InlineScript runat="server">
<script>
// Add .button() stuff here - note that InlineScript is last
// so the previous (control) DOM nodes exist already in current
// browser implementations, even if there is no "DOM loaded" per-se...
// -- or --
jQuery(function ($) {
// Add .button() stuff here; using $.ready here might (??)
// actually cause the browser to update the UI first...
// ...but it will guarantee the DOM is completely loaded.
})
</script>
</InlineScript>
</UpdatePanel>
https://stackoverflow.com/questions/10272665
复制相似问题