[英]JQuery Code For Selecting Select Option & Clicking Button Not Working?
嗨,我正試圖選擇大號,然后從網站上單擊按鈕。 我有小提琴中的html代碼以及我嘗試過的jquery代碼。 我已經嘗試過這些(下面),但是似乎沒有用。 我做錯了什么?
這是用於選擇大尺寸:
$('select[name="size"] option').filter(function () { return $(this).html() == "Large"; }).attr("selected",true);
這是用於單擊按鈕的:
$('#add-remove-buttons').find('.button').trigger('click');
這是我嘗試過的小提琴:
http://jsfiddle.net/8RnBf/645/
-謝謝
$('#add-remove-buttons').find('.button').on('click',function(e){
alert($('select[name="size"]').val());
});
我只更改了jQuery,如果這是您想要捕獲單擊時在下拉列表中選擇的內容。
解決方案: 演示
在執行此操作之前,請確保DOM已准備就緒
$('select#size').val(39304).find('option[value="39304"]').attr('selected','selected')
$('#size').change(function(){
$( "#size option:selected" ).each(function() {
console.log( $( this ).text() );
});
})
嘗試這個:
$('#size').val($('#size option').filter(function(ind, el) {
return $(el).text() === 'Large';
}).val());
演示: http : //jsfiddle.net/rLerzj08/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.