如何更改当前按钮(单击时),而不是页面上的所有按钮,其中shold我放了“this”元素
$(document).ready(function() {
$(function() {
// run the currently selected effect
function runEffect() {
// get effect type from
var selectedEffect = "blind";
// most effect types need no options passed by default
var options = {};
// some effects have required parameters
// run the effect
$( ".button" ).toggle( selectedEffect, options, 1000);
};
// set effect from select menu value
$('.moreshide').click(function(){
$(this).toggleClass('oks');
runEffect();
});
});
});
答案 0 :(得分:0)
您必须将clicked元素的引用传递给runEffect函数。然后在该部分中找到最近的部分ID和按钮类。
function runEffect(obj) {
// get effect type from
var selectedEffect = "blind";
// most effect types need no options passed by default
var options = {};
// some effects have required parameters
// run the effect
$(obj).closest('#chef').find(".button").toggle(selectedEffect, options, 1000);
};
$('.moreshide').click(function(){
$(this).toggleClass('oks');
runEffect(this);
});