【发布时间】:2015-07-20 10:43:45
【问题描述】:
我正在使用带有选择元素的 ddslick 插件。
<select name="category" id="cat">
<option cat_type="2" value="cat1" id="hello">Category1</option>
<option cat_type="1" value="cat2" id="hello2">Category2</option>
</select>
在此处选择类别时,我需要获取所选值cat_type。我尝试如下。
$('#cat').ddslick({
width: "100%",
onSelected: function (data) {
console.log(data.selectedData);
}
});
输出
Object { text="Category1", value="cat1", selected=true, more...}
但 cat_type 属性不存在。如果有人对 ddslick 插件有经验,请帮助我。
我已经检查了 select 标签的 html 源代码。但它不包含该属性。
<div id="cat" class="dd-container" style="width: 100%;">
<div class="dd-select" style="width: 100%; background: none repeat scroll 0% 0% rgb(238, 238, 238);">
<input type="hidden" class="dd-selected-value" value="cat2"><a class="dd-selected">
<label class="dd-selected-text">Category2</label></a><span class="dd-pointer dd-pointer-down"></span>
</div>
<ul class="dd-options dd-click-off-close" style="width: 100%; display: none;">
<li><a class="dd-option"> <input type="hidden" value="cat1" class="dd-option-value"> <label class="dd-option-text">Category1</label></a>
</li>
<li><a class="dd-option dd-option-selected"> <input type="hidden" value="cat2" class="dd-option-value"> <label class="dd-option-text">Category2</label></a>
</li>
</ul>
【问题讨论】:
-
它确实说“更多...”。你试过
console.log(data.selectedData['cat_type']);吗? -
@SandyChapman 我试过了,但输出是
undefined -
我认为你必须使用像
.$(this).attr("cat_type");这样的事件对象 -
@brroshan 我也试过这个。输出为
undefined
标签: jquery jquery-plugins