设置"标题"使用敲除选择后从下拉列表中选择的值

时间:2016-09-29 12:33:58

标签: javascript jquery knockout.js title knockout-mvc

我在ASP.NET MVC中使用knockout js。我想在选择下拉列表后,当用户将鼠标悬停在所选值上时,在标题上显示所选值的文本。因此,如果隐藏的较大值可以显示在标题中。 喜欢:如果我有三个值One,Two,BiggerValuethathidden。

所以现在很明显,如果我的下拉大小不像第三个值那么大,我的第三个值将在为dropdownlist定义的大小后隐藏。所以我想在悬停时将值设置为标题时显示。

现在我尝试像这样实现dropdownlist绑定:

  <select class="form-control" data-bind="options: Accounts, optionsCaption: ' -- ', optionsText: function (item) { return item.AccountName }, optionsValue: function (item) { return item.Id }, value:AccountId, click: setTitle" required="required" data-parsley-required-message="Account is required" id="ddlAccounts">

要经过这么多次搜索后设置,我试图这样做:

<div title="" id=dvAccount">
      <select class="form-control" data-bind="options: Accounts, optionsCaption: ' -- ', optionsText: function (item) { return item.AccountName }, optionsValue: function (item) { return item.Id }, value:AccountId, click: setTitle" required="required" data-parsley-required-message="Account is required" id="ddlAccounts">
</div>

根据Solution点击事件功能:

setTip = function(c, event){
            var element = event.currentTarget;
            var qref = element.getAttribute('Qref');
            var click_id = element.id;
            return true;
        }

我哪里错了?

请有人帮助我做这个棘手的伎俩!

2 个答案:

答案 0 :(得分:1)

您可以使用“attr”绑定(“attr:{title:AccountId}” - 您可以放置​​另一个(人类可读)值而不是AccountId):

#lightgallery a {
    width: calc(100% / 3);
    height: 240px;

    text-decoration: none;
    position: relative;    
}

a[href*="youtu"]::before {
    font-family: 'FontAwesome';
    content: "\f144";
    font-size: 2.5em;

    position: absolute;      
    top: 0;
    left: 0;
    width: 100%;             
    height: 100%;            
    display: flex;             
    justify-content: center;  
    align-items: center;     
}

答案 1 :(得分:0)

Uffffff是意外或者我不知道但是从最后3个问题我问了问题,我自己发布了我的答案,这次又是。

我找到了一个非常有用的解决方案,用于下拉选择值的标题:

只需使用此jquery和css组合:

$('select').each(function(){
            var tooltip = $(this).tooltip({
                selector: 'data-toggle="tooltip"',
                trigger: 'manual'
            });
            var selection = $(this).find('option:selected').text();
            tooltip.attr('title', selection)

            $('select').change(function() {
                var selection = $(this).find('option:selected').text();
                tooltip.attr('title', selection)
            });
        });

感谢TSV提供更快的响应并帮助我,但根据我的申请,这个更好。

相关问题