1

我有一个带有 5 个网格和 1 个按钮的网页。我想对页面进行编程以允许用户单击一个按钮并更改 5 个网格上的文本大小。我如何使用 jQuery 来做到这一点?

4

1 回答 1

0

以下是具有单个按钮的一种实现,该按钮在页面上特定区域的某些预定字体大小之间循环:

// Our fontsizes, and cached selectors
var fontsizes = ['10px', '16px', '20px', '30px'],
    $buttonEl = $("#modify"),
    $affected = $("#affected"),
    index;

// When our button is clicked
$buttonEl.on("click", function () {
    // Determine new font-size for the affected region
    $affected.css("font-size", function (index, size) {
       // Get index of current size in our array
       index = $.inArray(size, fontsizes);
       // Return the next font size in the list (wraps)
       return fontsizes[++index % fontsizes.length];
    });
});

演示:http: //jsfiddle.net/MLVAJ/1/

于 2012-11-26T16:23:33.137 回答