WordPress自定义下拉列表

时间:2016-11-12 作者:Vacsi Bálint

I have a site with a database of repair shops, by; Manufacturer - Venue

I want 2 dropdown lists at the home page.

In the first dropdown, when i select the "Apple" the second list appears in the places where they are "Apple" repair shops, and when i press the "Submit" button, it redirects me to its page.

Like;When i select in the first dropdown "Apple"It lists: -1-2-3-4-5-6-7

When i select "7" and press "SUBMIT" redirect to: mysite.com/7.

How can i do it?:l

1 个回复
SO网友:Third Essential Designer

像这样填充您的数据,您可以使用Javascript/jQuery来实现这一点。

<select class=\'apple_store_location\'>
<option value=\'1\' data-url="http://mysiteurl.com/1"> Place 1</option>
<option value=\'2\' data-url="http://mysiteurl.com/2"> Place 2</option>
<option value=\'3\' data-url="http://mysiteurl.com/3"> Place 3</option>
<option value=\'4\' data-url="http://mysiteurl.com/4"> Place 4</option>
<option value=\'5\' data-url="http://mysiteurl.com/5"> Place 5</option>
<option value=\'6\' data-url="http://mysiteurl.com/6"> Place 6</option>
<option value=\'7\' data-url="http://mysiteurl.com/7"> Place 7</option>
</select>

<script>
//Using jQuery
jQuery(document).ready(function($) {
    $(\'.apple_store_location\').change(takeMe2URL);
    function takeMe2URL() {
       var new_url =  $(\'option\',this).data(\'url\');
       window.location.replace(new_url);
    }
});

</script>

相关推荐

带有wp_Dropdown_Pages的下拉菜单

尝试创建一个下拉菜单,其中项目是给定父页面的子页面。该列表具有自动提交脚本。我想添加一些css规则,但无法这样做。此外,每次我编辑测试代码的页面时,我都会看到下面的警告:无法修改标题信息-标题已由发送(输出开始于/etc)非常感谢这是代码,不是我的:sourcefunction dropdownbox_autosubmit() { wp_dropdown_pages(array(\'child_of\' => 42,\'show_option_none=Select Page\'))