質問

私はBlackBerryのWebWorksと一緒に働いています。 何人か1が私を助けることができることを願っています

html

<select name="motherCat" onchange="motherChanged(event)">
    <option value="0">option0</option>
    <option value="1">option1</option>
    <option value="2">option3</option>
</select>

<select id="subCategory">
    <option value="0">wait mother change to fill</option>
</select>
.

JavaScript

function motherChanged(event){
    alert("motherChanged");
    var retCategory =subcategories[event.target.value];
    var fin = retCategory.length;
    var slCat = $('subCategory');
    slCat.length = 0;
    for(var i = 0;i<fin;i++){
        slCat.options.add(new Option(retCategory[i].text,retCategory[i].value));
    }
}
.

役に立ちましたか?

解決

onchangeプロパティを設定する方法にあります。eventは未定義です。むしろ定義されるものを使う:

<select name="motherCat" onchange="motherChanged(this)">
.

thisパラメータは選択要素自体になります。もちろん、パラメータを受け入れる機能もあり、thisを省略することもできます。

他のヒント

を使うこともできます

<select name="motherCat" onchange="motherChanged">
.

とJavaScriptは、イベントをパラメータとして関数を呼び出す必要があります。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top