[英]Set “title” of selected value from dropdown after selection using knockout
我在ASP.NET MVC中使用剔除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>
基於解決方案的 click事件功能:
setTip = function(c, event){
var element = event.currentTarget;
var qref = element.getAttribute('Qref');
var click_id = element.id;
return true;
}
我要去哪里錯了?
請有人幫我做這個棘手的把戲!
您可以使用“ 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>
是偶然的還是我不知道,但是從最近的三個問題中我問了一個問題,我本人再次發布了我的答案。
我發現下拉選擇值標題的極有用的解決方案:
只需使用此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如此快速的響應並為我提供幫助,但是根據我的應用程序,這是更好的選擇。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.