2016-09-29 50 views
0

我正在使用ASP.NET MVC淘汰js。當用戶在下拉菜單中選擇後,將鼠標懸停在所選值上時,我想在標題上顯示選定值的文本。所以如果更大的價值隱藏可以顯示在標題。 像:如果我有三個值一,二,BiggerValuethathidden。選擇使用敲除後從下拉列表中選擇值的「標題」

所以現在很明顯,如果我的下拉尺寸沒有像第三個值那麼大,我的第三個值將隱藏在爲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> 

點擊事件函數基於on Solution

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

我在哪裏出錯了?

請有人幫我做這個棘手的把戲!

回答

1

您可以使用 「ATTR」 結合( 「ATTR是:{title:ACCOUNTID}」 - 你可以把另一個(人類可讀)值,而不是ACCOUNTID):

<div data-bind="attr: { title: AccountId }" 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> 
+0

感謝您的回覆我正在嘗試它,但AccountId是Id。我想顯示它的文本。 –

+0

我不知道你的視圖模型的結構,我寫過,你可以使用,而不是「AccountId」另一個人類可讀字段的名稱... – TSV

+0

你的意思是說我可以設置文本,就像我有設置值並使用該變量而不是AccountId,對! –

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這種更快的響應速度,並幫助我,但是這一個是根據我的申請更好。

相關問題