选择下拉值是不是在改变?

时间:2015-05-07 17:14:47

标签: jquery drop-down-menu

这里我试图更改点击按钮的下拉值。但它没有用。

你能帮我吗?

// set option by value - select "option 2"
$('#btn').click(function() {
  $('#post-display-preference-select').val('2');
});
.btn {
  height: 30px;
  line-height: 25px;
  background-color: black;
  color: #fff;
  border: none;
}
<div>
  <table width="100%">
    <tr>
      <td align="center" style="font-size:14px;">

      </td>
      <td align="right">
        <select id="post-display-preference-select">
          <option value="1" selected="selected">Today</option>
          <option value="2">Last Week</option>
          <option value="3">Oldest</option>
        </select>
      </td>
    </tr>
  </table>
</div>

<button id="btn" class="btn">Select "Option 2"</button>

这是jsfiddle

1 个答案:

答案 0 :(得分:-1)

You didn't select jquery in your jsfiddle

试试这个:

 https://jsfiddle.net/0n74x7ht/3/