我有一個表格<select>
元素。這種選擇有<options>
我需要使用jQuery巡迴所有<options>
,並添加屬性disabled="disabled"
如果文本(該選項所示)不與開始「 - 」Jquery:如何將屬性disabled =「disabled」添加到選擇表單的選項?
看看圖片,看看我的意思。
我有一個表格<select>
元素。這種選擇有<options>
我需要使用jQuery巡迴所有<options>
,並添加屬性disabled="disabled"
如果文本(該選項所示)不與開始「 - 」Jquery:如何將屬性disabled =「disabled」添加到選擇表單的選項?
看看圖片,看看我的意思。
$("select").find("option").each(function(i,e) {
var t=$(e).text();
if (t.replace(/^\-/,'')==t) e.disabled=true;
});
編輯的0指數其實更好,但隨後e.disabled更兼容的瀏覽器; &發現是快
所以
$("select").find("option").each(function(i,e) {
var t=$(e).text()['0'];
if (t!=='-') e.disabled=true;
});
$("YourSELECT options").each(function(){
if(!$(this).html().startsWith("-"))
{
$(this).attr("disabled","true");
}
});
String.prototype.startsWith = function(str)
{return (this.match("^"+str)==str)}
我只是需要鱈魚首先,有幾種方法可以做到這一點。 Downvotes ......爲什麼??? – Jaso2970