如果禁用值,则Select = null的Val

时间:2017-04-26 11:22:32

标签: javascript jquery

我有Select并禁用所有值,如何将值设置为Select?

driver.findElement(By.xpath("//table[@id='ctl00_pagecontent_ctl01']/..//following::tr[@class='ui-widget-content jqgrow ui-row-ltr']/td[1]/a")).click();

jsfiddle

2 个答案:

答案 0 :(得分:3)

您必须具体说明要返回的元素的值。

alert($("#testselect option:selected").val());
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<select id="testselect">
  <option disabled>1</option>
  <option disabled>2</option>
  <option disabled selected>3</option>
</select>

答案 1 :(得分:3)

试试这个==&gt;

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>

相关问题