我的下拉列表如下,
<select name="speed" id="ddlCustomer" class="form-control select-basic">
<optgroup label="CustomerId OrderDate SupplyDate Supplier">
<option value="1011_2">1011 2015-12-18 2015-12-22 ABC</option>
<option value="1011_2">1034 2015-12-23 2015-12-28 XYZ</option>
</optgroup>
</select>
目前下拉列表显示“1011 2015-12-18 2015-12-22 ABC”等选项,这很好,但是当用户选择一个选项时,我只需要显示“CustomerId”,即1011。
非常感谢您的帮助。感谢
添加了关注焦点的脚本
customSelect.focusout(function () {
customSelectOptions.each(function (options) {
if ($(this).is(':selected')) {
$(this).text($(this).attr('value').split('_')[0]);
$(this).blur();
}
});
});
答案 0 :(得分:2)
答案 1 :(得分:1)
尝试这样。您使用带有所选选项文本值的正则表达式。
Jennyfer, I think you have to first do swipe logic in your listview.
Bellow library to make the items in a ListView dismissable with the possibility to undo it, using your own view to providing this functionality like the Gmail app for Android does.
for swipe to call you can refer bellow link.
https://github.com/hudomju/android-swipe-to-dismiss-undo
after that you can add calling functionality.like that
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:0377778888"));
startActivity(callIntent);
var ddlCustomer = document.querySelector('#ddlCustomer');
ddlCustomer.addEventListener('change',function(){
text = $(this).find("option:selected").text();
var value = text.match(/[0-9]+/);
$(this).find("option:selected").text(value);
alert(value);
});
答案 2 :(得分:0)
document.getElementById('#ddlCustomer').onchange = function() {
var option = this.options[this.selectedIndex];
option.setAttribute('data-text', option.text);
option.text =$(this).val();
// Reset texts for all other but current
for (var i = this.options.length; i--; ) {
if (i == this.selectedIndex) continue;
var text = this.options[i].getAttribute('data-text');
if (text) this.options[i].text = text;
}
};