ddslick selectText不工作或出现两次

时间:2015-12-10 03:00:34

标签: jquery jquery-plugins

根据plugin documentation

  

selectText默认值'选择...'设置默认文本时显示   没有选择任何选项。

她在下面的代码片段中使用了selectText,但它没有出现

	jQuery(document).ready(function(){
		jQuery('#demo-htmlselect').ddslick({
			selectText: "Select your favorite social network",
		});
	});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="http://sumankc.com/ddslick/jquery.ddslick.min.js"></script>
<select id="demo-htmlselect">
    <option data-description="Description with Facebook" data-imagesrc="http://dl.dropbox.com/u/40036711/Images/facebook-icon-32.png" value="0">Facebook</option>
    <option data-description="Description with Twitter" data-imagesrc="http://dl.dropbox.com/u/40036711/Images/twitter-icon-32.png" value="1">Twitter</option>
    <option data-description="Description with LinkedIn" data-imagesrc="http://dl.dropbox.com/u/40036711/Images/linkedin-icon-32.png" value="2">LinkedIn</option>
    <option data-description="Description with Foursquare" data-imagesrc="http://dl.dropbox.com/u/40036711/Images/foursquare-icon-32.png" value="3">Foursquare</option>
</select>

然后,我首先尝试使用选项字段来显示选择文本,现在它在下拉列表中显示两次

jQuery(document).ready(function(){
		jQuery('#demo-htmlselect').ddslick({
			selectText: "Select your favorite social network",
		});
	});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="http://sumankc.com/ddslick/jquery.ddslick.min.js"></script>
<select id="demo-htmlselect">
    <option>Select your favourite network</option>
    <option data-description="Description with Facebook" data-imagesrc="http://dl.dropbox.com/u/40036711/Images/facebook-icon-32.png" value="0">Facebook</option>
    <option data-description="Description with Twitter" data-imagesrc="http://dl.dropbox.com/u/40036711/Images/twitter-icon-32.png" value="1">Twitter</option>
    <option data-description="Description with LinkedIn" data-imagesrc="http://dl.dropbox.com/u/40036711/Images/linkedin-icon-32.png" value="2">LinkedIn</option>
    <option data-description="Description with Foursquare" data-imagesrc="http://dl.dropbox.com/u/40036711/Images/foursquare-icon-32.png" value="3">Foursquare</option>
</select>

如何在初始时实现单个selectText?

1 个答案:

答案 0 :(得分:1)

听起来不是很吵,但是......

根据插件文档:

  

为自定义下拉列表创建一个空占位符:例如:

<div id="myDropdown"></div>

使用div代替select,它会起作用。

jQuery(document).ready(function(){
		jQuery('#demo-htmlselect').ddslick({
			selectText: "Select your favorite social network",
		});
	});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="http://sumankc.com/ddslick/jquery.ddslick.min.js"></script>
<div id="demo-htmlselect">
    <option data-description="Description with Facebook" data-imagesrc="http://dl.dropbox.com/u/40036711/Images/facebook-icon-32.png" value="0">Facebook</option>
    <option data-description="Description with Twitter" data-imagesrc="http://dl.dropbox.com/u/40036711/Images/twitter-icon-32.png" value="1">Twitter</option>
    <option data-description="Description with LinkedIn" data-imagesrc="http://dl.dropbox.com/u/40036711/Images/linkedin-icon-32.png" value="2">LinkedIn</option>
    <option data-description="Description with Foursquare" data-imagesrc="http://dl.dropbox.com/u/40036711/Images/foursquare-icon-32.png" value="3">Foursquare</option>
</div>