我需要一些jQuery的幫助,我敢肯定它很愚蠢,但讓我陷入困境。在第一個下拉列表中是產品列表。第二個是與產品相關的內容列表。我需要顯示/隱藏第二個下拉菜單中的內容,具體取決於第一個選擇的內容。使用正則表達式與jQuery從下拉菜單中選擇選項
例如:如果我在第一個列表中選擇「FOO」,值爲1213,我需要從第二個列表中選擇值1213-3973和1213-3953。這兩個菜單中的值顯然都是動態的,但會始終具有給定的格式,即:contentselect選項中的值始終爲{product_id} - {content_id}
起初,對於html沒有超級知識,有一個自定義屬性設置在contentselect形式,我有我的jquery選擇器抓取。但是,似乎並非所有瀏覽器都喜歡自定義屬性。
因爲它現在,我不知道該怎麼做。我被告知我需要某種正則表達式,但我不確定從哪裏開始。
<script>
function selectProduct()
{
//reset form
$('.form_contentselect option:selected').removeAttr("selected");
var product_selected = $('.form_productselect option:selected').val();
$('.form_contentselect').hide();
/////////HELP HERE PLEASE//////////
//$('.form_contentselect option[???????????]').hide(); //HIDE irrelevant content
//$('.form_contentselect option[???????????]').show(); //SHOW associated content
///////////////////////////////////
$('.form_contentselect').show();
}
</script>
<div class="form_productselect">
<div class="form_item">
Select Product:
<select name="product_id" onchange=selectProduct()>
<option value="0" selected="selected">--</option>
<option value="1213" >FOO</option>
<option value="1315" >BAR</option>
</select>
</div>
</div>
<div class="form_contentselect">
<div class="form_item">
Select Content:
<select name="content_id">
<option value="0" selected="selected">--</option>
<option value="1213-3973" >FOO - 100 points</option>
<option value="1213-3953" >FOO - 1000 points</option>
<option value="1315-3965" >BAR - 100 points</option>
<option value="1315-3949" >BAR - 1000 points</option>
</select>
</div>
</div>
如果第二元件是'多個= 「多個」'? – Oybek 2012-02-07 13:29:48
對不起。現在我明白你想要什麼了。只留下那些相關的值。 – Oybek 2012-02-07 13:31:12
http://api.jquery.com/attribute-starts-with-selector/,但是用ajax動態加載內容將是一個更好的方法 – 2012-02-07 13:31:14