【发布时间】:2011-11-24 20:34:28
【问题描述】:
我的应用(单页布局)从服务器接收数据,我想要一个漂亮的基于按钮的导航,例如:
<a data-role="button">Button X</a>
<a data-role="button">Button Y</a>
非常直接。当用户在程序中来回移动时,我想重用我的 div,所以我在使用 append() 插入新按钮之前调用$('#fancyDiv').empty() - 根据程序状态。
好的,但现在我们遇到了麻烦。只有在第一次通话按钮才能正确显示。当我返回时,选择另一个菜单项并刷新页面(调用empty() 和append())除了纯文本之外没有任何按钮。
最小化我的代码吧,好像 jQuery 不喜欢附加 HTML 锚标签。
您可以在下面找到一些要在 Web 浏览器中打开的 HTML 代码。附加第二个文本时,您可以看到链接没有着色,而是被忽略并显示为常规文本。
我还尝试了 html() 和 text() 方法导致相同的结果,所以我很感激任何想法。
<html>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.js"></script>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.css" />
<script src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
<script src="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.js"></script>
<body>
<a data-role="button" onclick="$('#text').empty();">Empty paragraph</a>
<a data-role="button" onclick="$('#text').append('wawon Park is a park that is located in Daegu Dalseong-gun, South Korea. The people who mainly use the park are children. It is marked to park, <a>1981 March 10.</a>')">Attach new Text</a>
<p id="text">Hod Stuart (1879-1907) was a <a>Canadian professional</a> ice hockey cover-point (now known as a defenceman) who played nine seasons for several teams in different leagues. He also played briefly for the Ottawa Rough Riders football team</p>
<h3>Reference Text</h3>
<p>wawon Park is a park that is located in Daegu Dalseong-gun, South Korea. The people who mainly use the park are children. It is marked to park, <a>1981 March 10.</a></p>
</body>
</html>
* 编辑/更新 *
好的,Rory McCrossan 提出了一个非常好的建议,即手动将 ui-link 类添加到锚元素。这在技术上解决了我的问题,但更进一步,出现了一个新问题。我很确定是否为此打开一个新问题:
如前所述,我想使用按钮进行导航,仅向它们添加 ui-link 类是不够的。我用萤火虫检查了this fiddle,似乎缺少某种启动方法。 这是工作按钮的代码:
<a class="ui-btn ui-btn-up-c ui-btn-corner-all ui-shadow" data-role="button" data-theme="c">
<span class="ui-btn-inner ui-btn-corner-all" aria-hidden="true">
<span class="ui-btn-text">1981 March 10.</span>
</span>
</a>
我们在这里找到附加的按钮:
<a class="ui-link" data-role="button">1981 March 10.</a>
好的,又快又脏,我可以自己复制代码并设置所有跨度,但这听起来....错误,一旦 jQuery 的结构发生一些变化就会中断。
【问题讨论】:
-
你不能在另一个 中有 - 它不是有效的标记
-
你能澄清你的意思吗?我能看到的唯一嵌套 是按钮 + oncllick=...append() 结构。