在输入场上使用onfocus打开手风琴

时间:2015-05-30 12:42:44

标签: javascript jquery

我正试图在输入场上打开onfocus手风琴。我已经尝试了但它没有发生。我想根据输入框是焦点打开手风琴

<input type="text" id="rnv" class="form-control"  placeholder="Ex: Roasted Aparagus and Musherooms" onfocus="accordion('rntip',this)">

<textarea class="form-control"  id="in" rows="6" placeholder="Ex: bunch fresh asparagus, trimmed; 2 sprigs fresh rosemary, minced" onfocus="accordion('intip',this)"></textarea>  
<script type="text/javascript">

function accordion(id,obj){
$(document).ready(function(){

        var accordion = id; 
        var accordionContent = accordion.next('.accordion-content');
        var accordionToggleIcon = $(this).children('.toggle-icon');

        // toggle accordion link open class
        accordion.toggleClass("open");
        // toggle accordion content
        accordionContent.slideToggle(250);

        // change plus/minus icon
        if (accordion.hasClass("open")) {
            accordionToggleIcon.html("<i class='fa fa-minus-circle'></i>");
        } else {
            accordionToggleIcon.html("<i class='fa fa-plus-circle'></i>");
        }
});     


}
</script>

 <div class="accordion-container"> <a href="#" class="accordion-toggle1" id="rntip"> <span class="toggle-icon"><i class="fa fa-plus-circle"></i></span>Recipe Name</a>
                  <div class="accordion-content">
                    <ul>
                      <li>Keep it short.</li>
                      <li>Include the name of the dish or its main ingredients.</li>
                      <li>Add a personal touch/get creative.</li>
                    </ul>
                  </div>
</div>

1 个答案:

答案 0 :(得分:0)

确保accordion引用accordion元素,而不仅仅是您传递的字符串。

var accordion = id;更改为var accordion = $("#"+id);