简体   繁体   English

如何在tablepress的下拉菜单下显示当前选定的值选项?

[英]How to have the current selected value option under dropdown in tablepress?

I would like to know how to have the selected option value under dropdown after selecting it, because whenever I'm selecting any option, it gets deleted and comes beneath the dropdown option with a link. 我想知道选择后如何在下拉菜单中具有选定的选项值,因为每当我选择任何选项时,它都会被删除并位于带有链接的下拉选项下方。 When you click it, it is going back to the dropdown menu. 当您单击它时,它会返回到下拉菜单。 Code before selection 选择之前的代码

<div class="column-filter-widget">
    <select class="widget-0">
        <option value="">Healthy Life</option>
        <option value="Fruit">Fruit</option>
        <option value="Vegetable">Vegetable</option>
       <option value="Beef">Beef</option>
    </select>

HTML Code after selecting option as "Fruit" 选择选项为“水果”后的HTML代码

<div class="column-filter-widget">
     <select class="widget-0">
         <option value="">Healthy Life</option>
         <option value="Vegetable">Vegetable</option>
         <option value="Beef">Beef</option>
     </select><a class="filter-term filter-term-fruit" href="#">Fruit</a>
 </div>

Css Code: CSS代码:

  .column-filter-widgets a.filter-term:hover {text-decoration: line-through!important;}

Here is the javasript file Click here to check javascript file. 这是javasript文件单击此处检查javascript文件。 I know there are many threads similar to that but since this problem is for Wordpress Plugin tablepress datatables column filter widgets and it's under javascript file which I don't know how to solve. 我知道有很多与此类似的线程,但是由于此问题是针对Wordpress插件tablepress datatables列过滤器小部件而来的,所以它位于javascript文件下,我不知道如何解决。 I'm sure the problem can easily be solved after looking at the above link. 通过查看以上链接,我相信该问题可以轻松解决。

Thanks 谢谢

Try this, i'm assuming this what you were after from what i read, here's a JS Fiddle to show you http://jsfiddle.net/7a38ast6/7/ 试试看,我假设这是我从阅读中得到的东西,这是一个JS小提琴,向您展示http://jsfiddle.net/7a38ast6/7/

JQuery jQuery查询

var optionvalue = 0;
var optionvalueclass = ""

$('select.widget-0').change(function(){
    optionvalue = $('option:selected', this).text();
    optionvalue = optionvalue.replace(" ", "-");
    optionvalueclass = optionvalue.toLowerCase();
    $(".widget-0").after('<a class="filter-term filter-term-' + optionvalueclass + '" href="#">' + optionvalue + '</a>');
    $('option:selected', this).remove();
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM