jquery - 无法在 jQuery UI 按钮内动态附加 FontAwesome 图标

标签 jquery jquery-ui accordion

在我的项目中,我有一个 jQuery UI Accordion ,每个部分都有几个按钮。单击这些按钮后,我将通过 AJAX 将数据加载到另一个 <div> 中.

为了显示 Accordion 内的菜单处于事件状态,我计划显示 FontAwesome eye icon Accordion 按钮内部,如下所示:http://jsfiddle.net/Vw9Z6/11/ .

但是,这不起作用。 HTML 已附加,但图标未显示。

$("div#accordion").accordion({ heightStyle: "content", collapsible: true});

$("input[type=button]").button();

$("input[type=button]").click(function(){
  $(this).append($("<i class='fa fa-eye'></i>"));
});
input[type="button"]{
  display: block;
  width: 100%;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js"></script>

<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/themes/smoothness/jquery-ui.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.3.0/css/font-awesome.css" />


<div id="accordion">

  <h3><a href="#">Section 1</a></h3> <!-- consider just this section -->

  <div>
    <input type="button" value="Lorem" />
    <input type="button" value="Ipsum" />
  </div>
  <h3><a href="#">Section 2</a></h3>

  <div>
    <p>Section 2 Content</p>
  </div>
  <h3><a href="#">Section 3</a></h3>

  <div>
    <p>Section 3 Content
      <br />Use caution - and notice that if you have really long content it may be difficult to see the accordion section links. And the longest section sets the height for all of the sections.
      <br /><a href="http://huwshimi.com/comic/"><img src="http://dotnet.tech.ubc.ca/CourseWiki/images/a/a5/You_must_be_this_tall.png" style="border:none;width:300px"/></a>

    </p>
  </div>
  <h3><a href="#">Section 4</a></h3>

  <div>
    <p>Section 4 Content
      <br />Thanks for reading all four sections.</p>
  </div>
</div>

等效 fiddle :http://jsfiddle.net/d6mSA/424/

我如何让它工作?

此外,最好的设置方法是什么,以便当单击另一个按钮时,眼睛图标移动到该按钮?

最佳答案

这里的问题是您无法附加 i元素到 input元素。

因此,如果您想让它正常工作,我可以建议您使用按钮(也许您需要检查您想要通过输入实现什么目标)。

一个非常简单且有效的 fiddle here .

HTML:

<div>
    <button>Lorem</button>
    <button>Ipsum</button>
</div>

Javascript:

$("div#accordion").accordion({ heightStyle: "content", collapsible: true});

$("button").button();

$("button").click(function(){
  $(this).append($("<i class='fa fa-eye'></i>")).button();
});

关于 <button> 的一个有趣问题与 <input type=“button” /> here .

关于jquery - 无法在 jQuery UI 按钮内动态附加 FontAwesome 图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28370861/

相关文章:

jquery - 需要像 functionailty 这样的 gmail - jquery 自动完成以包含姓名和电子邮件地址 - 在字符串搜索中

使用图标时,jQuery ui datepicker 未在焦点上打开

javascript - 想要改变多个 div 的颜色几秒钟,但仅限于最近加载的

css - 覆盖 jQuery UI Datepicker div 在第一页加载时奇怪地可见。

javascript - 如何动态添加国家标记?

javascript - 查找选中标签的标题

javascript - 通过 $(document).ready 传递范围

Jquery UI 选择菜单在对话框中不起作用

带有鼠标悬停/鼠标悬停的 jQuery Accordion 导航

html - 这些 css 可折叠 div 默认打开了吗?