2

我想根据我拥有的值通过 jquery 更改下拉选项。并根据该值显示文本有
html:-

<select id="OfferType">
 <option value="Unspecified" selected="selected">Unspecified</option>
 <option value="FreeOffer">Free Offer</option>
 <option value="LowOffer">Low Offer</option>
 <option value="AddOffer">Add Offer</option>
 <option value="PercentageOffer">Percentage Offer</option>
 <option value="GroupOffer">Group Offer</option>
</select>


在jQuery中

if (('filterby' in urlParams) && (urlParams['filterby'] == 'LowOffer')) {
    $("#OfferType").val("LowOffer");
    $('#OfferType option[value=LowOffer]').text('Low Offer');
     submitAjaxOffersSearch();
  }

数据根据val("LowOffer")排序,但在下拉文本中不是 Show text("LowOffer");

4

1 回答 1

-1
$('#OfferType').val('LowOffer'); //sets the value
alert($('#OfferType option:selected').text()); //gets the text

选择器 '#OfferType option:selected' 获取 id 为 OfferType (#OfferType) 的元素以及选择它们的选项 (option:selected)

jQuery val()

jQuery 文本()

于 2013-04-15T18:28:02.773 回答