如果禁用值,则Select = null的Val [英] Val of Select = null, if values is disabled

查看:60
本文介绍了如果禁用值,则Select = null的Val的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已选择并且所有值都已禁用,如何将值设置为此选择?

I have Select and all values is disabled, how can I set the value to this Select?

<select id="testselect">
   <option disabled>1</option>
   <option disabled>2</option>
   <option disabled selected="selected">3</option>
</select>

alert($("#testselect").val()); //result null

jsfiddle

推荐答案

试试这个==>

alert($('#testselect option[disabled]:selected').val());

<script src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
<select id="testselect">
  <option disabled>1</option>
  <option disabled>2</option>
  <option disabled selected>3</option>
</select>

这篇关于如果禁用值,则Select = null的Val的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆