{hero}

buttons().text()

自:Buttons 1.0.0 起

取得 / 設定所選按鈕的文字。
請注意 - 此屬性需要 DataTables 的 Buttons 擴充功能。

描述

此方法提供動態取得和設定一個或多個按鈕顯示文字的能力。 如果互動(例如列選擇)變更按鈕的行為,這會很有用,讓最終使用者知道行為的變更。

類型

function buttons().text()

描述

取得所選按鈕的顯示文字。

請注意,如果按鈕的 text 選項指定為函式,此方法將會執行該函式並返回結果,因此始終會返回字串。

回傳

DataTables API 實例,其中結果集包含所選按鈕的文字。

function buttons().text( set )

描述

設定所選按鈕的顯示文字

參數
回傳

DataTables API 實例,結果集中包含所選按鈕,可用於在按鈕上鏈接進一步的操作。

範例

取得所有按鈕的文字

var table = new DataTable('#myTable');
var buttonText = table.buttons().text();

console.log(buttonText.toArray());

使用 HTML 設定所有已停用按鈕的文字

var table = new DataTable('#myTable');

table.buttons('.disabled').text('<b>Not available</b>');

使用函式顯示文字

var table = new DataTable('#myTable');

table.buttons([0, 1]).text(function (dt, button, config) {
	return dt.i18n('buttons.input', 'Input');
});