第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

設(shè)置選擇框的選擇選項(xiàng)

設(shè)置選擇框的選擇選項(xiàng)

浮云間 2019-11-11 14:04:46
我想設(shè)置一個(gè)先前選擇的要在頁面加載時(shí)顯示的選項(xiàng)。我用以下代碼嘗試了它:$("#gate").val('Gateway 2');與<select id="gate">    <option value='null'>- choose -</option>    <option value='gateway_1'>Gateway 1</option>    <option value='gateway_2'>Gateway 2</option></select>但這是行不通的。有任何想法嗎?
查看完整描述

3 回答

?
慕神8447489

TA貢獻(xiàn)1780條經(jīng)驗(yàn) 獲得超1個(gè)贊

$(document).ready(function() {

    $("#gate option[value='Gateway 2']").prop('selected', true);

    // you need to specify id of combo to set right combo, if more than one combo

});


查看完整回答
反對(duì) 回復(fù) 2019-11-11
?
慕沐林林

TA貢獻(xiàn)2016條經(jīng)驗(yàn) 獲得超9個(gè)贊

我發(fā)現(xiàn)使用jQuery .val()方法有一個(gè)明顯的缺點(diǎn)。


<select id="gate"></select>

$("#gate").val("Gateway 2");

如果此選擇框(或任何其他輸入對(duì)象)在表單中,并且表單中使用了重置按鈕,則單擊重置按鈕時(shí),設(shè)置值將被清除,并且不會(huì)重置為您期望的初始值。


這似乎最適合我。


對(duì)于選擇框


<select id="gate"></select>

$("#gate option[value='Gateway 2']").attr("selected", true);

對(duì)于文字輸入


<input type="text" id="gate" />

$("#gate").attr("value", "your desired value")

對(duì)于文本區(qū)域輸入


<textarea id="gate"></textarea>

$("#gate").html("your desired value")

對(duì)于復(fù)選框


<input type="checkbox" id="gate" />

$("#gate option[value='Gateway 2']").attr("checked", true);

對(duì)于單選按鈕


<input type="radio" id="gate" value="this"/> or <input type="radio" id="gate" value="that"/>

$("#gate[value='this']").attr("checked", true);


查看完整回答
反對(duì) 回復(fù) 2019-11-11
  • 3 回答
  • 0 關(guān)注
  • 561 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)