var input = $('#csearchtext').val();
var dropdownindex = $("select[name='columnlist'] option:selected").index();
var radioselected = $("input:radio[name='group2']:checked").val();
var searchpattern = '';
switch (radioselected) {
case 1:
searchpattern = '/^'+input+'/'+'ig';
break;
case 2:
searchpattern = input;
break;
case 3:
searchpattern = '/'+input+'$/'+'ig';
break;
}
console.log(searchpattern);
$('#table_id').dataTable().fnFilter(searchpattern, dropdownindex + 1, false, true, true, false);
输入工作正常,以及下拉和无线电选择。Radioselected 是 1,2 或 3,并且 2 是默认选中的,尽管 console.log searchpattern 仍然是空的,但 switch 语句应该每次都生效。