【问题标题】:I have to post select options on change with PHP, but select is being converted to ul li by JQuery我必须在使用 PHP 更改时发布选择选项,但选择正在通过 JQuery 转换为 ul li
【发布时间】:2013-05-26 21:29:44
【问题描述】:

我正在使用样式选择下拉菜单,来自here

我想发布所选选项,以便为其他下拉菜单呈现一些数据。

问题出在

 onChange="this.form.submit()"

不起作用,因为 JQuery 将选择选项更改为 ul > li... 任何解决方案都会得到解决.. 要么在同一个地方发帖, 或者有一个替代的 JQuery 选择,它不会将选择转换为 ul li。

select name="districtid" id="districtid" class="cd-select" > onChange="this.form.submit();" >

                   <option value="" selected>Select District</option>
                  <?php do {
                  ?>
                  <option value="<?php echo >$row_district['id'];?>"
                      <?php
                  if(isset($_GET['districtid']))

{ $pdistrict = $_GET['districtid']; if ($row_district['id'] == $pdistrict ) echo "selected";} ?>>

                      echo $row_district['name']; 

                       ?>
                   </option>

                   <?php } while ($row_district = >mysql_fetch_assoc($district)); ?>

【问题讨论】:

  • 你能告诉我们你正在使用的代码吗?
  • yes.. 用代码编辑.. 这个选择选项被表单
    code
    包围

标签: php jquery css select drop-down-menu


【解决方案1】:

试试这个

来自line 143-151jquery.dropdown.js 用下面的代码更新myform 是你的form's id.. 但它不会在页面加载时保留dropdown 状态,如果您想保留选中的下拉值,则可以使用cookie

this.opts.on( 'click.dropdown', function() {
            if( self.opened ) {
                var opt = $( this );
                self.options.onOptionSelect( opt );
                self.inputEl.val( opt.data( 'value' ) );
                self.selectlabel.html( opt.html() );
                if ($("#myform").length == 1) {
                $("#myform").submit();//submitting myform
                }
                self.close();
            }
        } );

【讨论】:

  • 这真是太棒了......它完成了工作......非常感谢......你能告诉我一件事,$(“#myform”).length == 1是什么意思?
  • @Fahad 如果它解决了您的问题,您可以将其标记为正确答案:)。
猜你喜欢
  • 2019-08-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-02-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多