duanfangfei5558
duanfangfei5558
2017-04-11 11:44
浏览 44

JQuery语法错误无法识别的表达式

$("#EMPLOYEE_ALT option:[value='"+$("#EMPLOYEE_ID").val()+"']").remove();

the above code gives the following error:

Uncaught Error: Syntax error, unrecognized expression: #EMPLOYEE_ALT\ option:[value='9999']

9999 is employee id witch is correct and this value suppose to be sent via ajax and return with something.

$.post("url", { emp: $("#EMPLOYEE_ID").val(),ajax: "yes"  },
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dongqiao2077
    dongqiao2077 2017-04-11 11:46
    已采纳

    You have unexpected : in your selector. The correct selector would be

    $("#EMPLOYEE_ALT option[value='"+$("#EMPLOYEE_ID").val()+"']").remove();
    
    点赞 评论
  • duanba3707
    duanba3707 2017-04-11 11:45

    Try this:

    "#EMPLOYEE_ALT option[value='"+$("#EMPLOYEE_ID").val()+"']"
    

    The attribute selector doesn't haves : on it. That is used for CSS's pseudo-classes only.

    $("#remove").on("click", function() {
        $("#EMPLOYEE_ALT option[value='9999']").remove();
    });
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    
    <select id="EMPLOYEE_ALT">
      <option value="1">1</option>
      <option value="9999">9999</option>
    </select>
    
    <button id="remove">Remove item '9999'</button>

    </div>
    
    点赞 评论

相关推荐