为什么isFunction
不能用于隐藏/显示?
http://jsbin.com/tavirasi/1/edit?js,output
$('.form select[data-change]').change(function(){
var $el = $($(this).data('change'));
if($el.length){
var action = $(this).find(':selected').data('action');
if($.isFunction(action)){
$el[action]();
}
}
}).change();
HTML
<form action="" class="form">
<select name="question" data-change="input[name=customer_question]">
<option data-action="hide">Mothers maiden name</option>
<option data-action="foo">Prevent error</option>
<option data-action="show">Custom question</option>
</select>
<input type="text" name="customer_question" style="display:none" />
</form>
答案 0 :(得分:2)
您传递的字符串当然不是函数。它应该是:
if ( $.isFunction( $el[action] ) )