Is there a way to use variable as conditional operators in javascript?

时间:2019-04-08 12:51:16

标签: javascript jquery html

I am trying to create a filter mechanism which takes higher and lower values and operators (=, <, <= etc.)

Screenshot

I have to filter data using jquery, i am able to fetch the data of the input and select field but unable to use the selected operators in if condition (i think it is not permitted to be used that way).

Here is the code

$("#filter_btn").click(function(){
    vol_low_sign = $("#f_vol_low_sign").val();
    vol_high_sign = $("#f_vol_high_sign").val();

    vol_low_val = $("#f_vol_low_val").val();
    vol_high_val = $("#f_vol_high_val").val();

    if (vol_low_val != "" || vol_high_val != "") {
        if (vol_low_sign != "") {
            if (vol_high_sign != "") {
                if (vol_low_val vol_low_sign vol || vol vol_high_sign vol_high_val) {
                    // do something
                    ...
                    ..
                    .

I am getting this error message "Uncaught SyntaxError: Unexpected identifier" because of the variable as operator. Is there any other way to achieve the task?

0 个答案:

没有答案
相关问题