开发者

JQuery option value sometimes undefined

I am having trouble with a simple select-option. Most of the time the selected-value (in the action var) yields the correct result ("closed") but sometimes it is "undefined".

$("#doaction").click(function () {
  // action sometimes is "undefined" =>
  var action = $("#workflow option:selected").val();        
}

<select name="workflow" id="workflow">
  <option value="-1">initial state</option>
  <option value="close">perform actio开发者_运维百科n close</option>
</select>

<a href="#" id="doaction">submit</a>

Any hints are welcome.


Why not just:

$("#workflow").val()

The val() method will return the current selected option of a select element.


Using

$("#workflow option:selected").val()

is equivalent to

$("#workflow").val()


You should do

$("#workflow").val();

See documentation

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜