问题描述
我正在使用ddslick来制作带有图标的下拉菜单,唯一的麻烦是当我发布表单时,所选选项的值始终为空,如果我关闭ddslick可以正常工作.
I am using ddslick to make drop down menu's with icons, the only trouble is when I post the form the value of the selected option is always empty, it works fine if I turn ddslick off.
<script language="javascript" type="text/javascript">
$('.cflagdd').ddslick({
onSelected: function(selectedData){
//callback function: do something with selectedData;
// $('#editcflag').submit(); - this does not work, posts form on page load
}
});
</script>
<select class="cflagdd" name="cflag">
<option value="0" selected="selected">No action flag set</option>
<option value="1" data-imagesrc="'.base_url().'images/Actions-flag-green-icon.png">Resolved</option>
<option value="2" data-imagesrc="'.base_url().'images/Actions-flag-yellow-icon.png">Investigate</option>
<option value="3" data-imagesrc="'.base_url().'images/Actions-flag-red-icon.png">Urgent</option>
<option value="4" data-imagesrc="'.base_url().'images/Actions-flag-blue-icon.png">False positive</option>
</select>
版本:jQuery的1.7.2.jsjQuery UI-v1.8.20
Versions:Jquery-1.7.2.jsjQuery UI - v1.8.20
非常感谢您,
推荐答案
ddslick中有一个错误,使隐藏的输入不具有name属性.
There's a bug in ddslick that leaves the hidden inputs without a name attribute.
我能够在ddslick上添加几行,使其能够将select的name属性添加到它创建的隐藏元素中.
I was able to add a couple lines to ddslick to get it to add the select's name attribute to the hidden element it creates.
首先,下载ddslick的未压缩版本: http://dl.dropboxusercontent.com/u/40036711/Scripts/jquery.ddslick.js
First, download the uncompressed version of ddslick: http://dl.dropboxusercontent.com/u/40036711/Scripts/jquery.ddslick.js
然后在第106行或以"var ddSelect = ..."开头的行之后添加以下内容:
Then add the following on line 106, or right after the lines starting with "var ddSelect = ..." :
// set hidden input name
ddSelect.find('input.dd-selected-value').attr('name', $(this).attr('name'));
这篇关于ddslick选择选项将不会发布所选选项的值-jQuery插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!