javascript - How to change Bootstrap dropdown selected item with Jquery? - Stack Overflow

I want to change Bootstrap dropdown item select with jQuery? I'm newbie in jQuery. I put dropdown

I want to change Bootstrap dropdown item select with jQuery? I'm newbie in jQuery. I put dropdown list data from database with foreach loop. and I've a button. that have "id" and "value". When I click on that button, i want to change my bootstrap dropdown 'li' selected item to it button's "vaule" and "id".Please help me.

<div class="dropdown" align="right">
    <input type="button" id="select_staff" class="btn btn-default btn-sm dropdown-toggle" type="button" data-toggle="dropdown" value="<?php echo $cur_admin_name ?> ▼">
    <ul id="admin_cal_list" class="dropdown-menu dropdown-menu-right">
    <input type="hidden" id="admin_id" class="form-control">
        <?php foreach ($admin_name as $admin_list): ?>
            <li id="<?php echo $admin_list["interview_plan_staff_id"]; ?>"><a href="#"><?php echo $admin_list["interview_plan_staff_name"]; ?></a></li>
        <?php endforeach; ?>
    </ul>
</div>

I want to change Bootstrap dropdown item select with jQuery? I'm newbie in jQuery. I put dropdown list data from database with foreach loop. and I've a button. that have "id" and "value". When I click on that button, i want to change my bootstrap dropdown 'li' selected item to it button's "vaule" and "id".Please help me.

<div class="dropdown" align="right">
    <input type="button" id="select_staff" class="btn btn-default btn-sm dropdown-toggle" type="button" data-toggle="dropdown" value="<?php echo $cur_admin_name ?> ▼">
    <ul id="admin_cal_list" class="dropdown-menu dropdown-menu-right">
    <input type="hidden" id="admin_id" class="form-control">
        <?php foreach ($admin_name as $admin_list): ?>
            <li id="<?php echo $admin_list["interview_plan_staff_id"]; ?>"><a href="#"><?php echo $admin_list["interview_plan_staff_name"]; ?></a></li>
        <?php endforeach; ?>
    </ul>
</div>
Share Improve this question edited Mar 1, 2017 at 8:42 Barry Michael Doyle 10.7k33 gold badges98 silver badges159 bronze badges asked Mar 1, 2017 at 4:07 Kyaw Zin WaiKyaw Zin Wai 4575 gold badges10 silver badges26 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 2

Like this..

$(".dropdown-menu li a").click(function(){
  var selText = $(this).text();
  console.log( selText);
  $(this).parents('.dropdown').find('.dropdown-toggle').val(selText);
});

Demo: http://www.bootply./EuFKxaQ2bO

I'm not sure I 100% understand what you are trying to do. For clarity, you want the li to change to the button's id and value? If so try this:

    $(".dropdown-menu li a").click(function(){
    document.getElementById("admin_cal_list").innerHTML = $(".dropdown-toggle").attr("id") + " " + $(".dropdown-toggle").attr("value");
});

Demo: http://www.bootply./UphW5kYtwE

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745378447a4625111.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信