我想展開jQuery Mobile可摺疊內容部分的可摺疊內容。我知道我可以點擊標題來展開它,但我不希望每次頁面刷新時都要依靠用戶點擊同一部分。我知道我可以在html中設置一個變量,但這不會執行,因爲可摺疊內容在回發時仍然會關閉。動態展開可摺疊內容
我需要用代碼而不是用戶來完成。您可以在下面看到我的失敗嘗試。我使用了VS 2013的Web Forms項目中的模板作爲開始,然後我添加了jQuery Mobile,並遵循了jQuery Mobile的site的指示,或者我想。這是一個簡化的測試頁面,但最終,我希望有一個ASP.NET變量來檢測回發時是否已經單擊某個節,並且如果已經單擊了可摺疊節,請再次打開它,以便用戶不會必須再次點擊相同的地方。有什麼辦法來保持擴展狀態或動態擴展jQuery Mobile的可摺疊內容嗎?
<%@ Page Title="Home Page" Language="VB" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Default.aspx.vb" Inherits="ExpandTest._Default" %>
<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
<script>
$(".myDiv").trigger("expand");
</script>
<div class="jumbotron">
<h1>ASP.NET</h1>
<p class="lead">ASP.NET is a free web framework for building great Web sites and Web applications using HTML, CSS and JavaScript.</p>
<p><a href="http://www.asp.net" class="btn btn-primary btn-large">Learn more »</a></p>
</div>
<div class="row">
<div class="myDiv" data-role="collapsible">
<h2>Getting Started</h2>
<p>ASP.NET Web Forms lets you build dynamic websites using a familiar drag-and-drop, event-driven model. A design surface and hundreds of controls and components let you rapidly build sophisticated, powerful UI-driven sites with data access.
</p>
<p>
<a class="btn btn-default" href="http://go.microsoft.com/fwlink/?LinkId=301948">Learn more »</a>
</p>
</div>
</div>
</asp:Content>
- 編輯 - 件事我已經試過(甚至只是概念驗證)失敗:
$(".myDiv").trigger('expand'); // Apparently does not execute
$('.myDiv').on("click", alert("Fe Fi Foo Bar!");); // does not run anything within
$(document).on("pagecreate", function() {
另外,我最近讀到document.ready
應該使用jQuery的但not jQuery Mobile。告訴我的事實是,我無法使用其他用戶似乎認爲可行的相同代碼以及已在jsfiddle中運行的相同代碼。這讓我相信我錯過了一些顯而易見的東西。我已經修改了加載jQuery Mobile與代碼無關的順序。
你有沒有在collapsible div中試過'data-collapsed =「false」'屬性?如果您使用JQM 1.4'$(「。selector」)。collapsible(「expand」);'。 – Omar
'data-collapsed =「false」'不管天氣如何,我都希望它是開放的,即它不是動態的。我正在使用JQM 1.4和'$(「。myDiv」)。collapsible(「expand」);'不能以我用它的方式工作。 –
@Omar如果$(「。myDiv」)。collapsible(「expand」);'以任何方式爲您工作我想知道何時何地加載JQM以及加載自定義腳本的時間和位置? –