オブジェクトの動的(ユーザー入力からの)値を作成したいが、私は "未定義"となる。アイデアは3つの入力フィールドを持つことで、ユーザーは警告メッセージをいっぱいにする値を入力する必要があります。オブジェクトのプロパティの動的値
<script type="text/javascript">
function Family (fatherName, motherName, sisterName) {
this.fatherName = fatherName;
this.motherName = motherName;
this.sisterName = sisterName;
this.myFamily = function() {
alert("My father's name is " + this.fatherName +", my mother's name is "+ this.motherName +" and my sister's name is " + this.sisterName +".");
}
}
var Me = new Family(
Family["fatherName"] = father,
Family["motherName"] = mother,
Family["sisterName"] = siter);
var father = document.getElementById("fatherId").value;
var mother = document.getElementById("motherId").value;
var sister = document.getElementById("sisterId").value;
</script>
<input type="text" id="fatherId" />
<input type="text" id="motherId" />
<input type="text" id="fatherId" />
<input type="submit" value="Send" onclick="Me.myFamily();">
また、ユーザーがプロパティを追加したり削除したりする方法も探しています(値も同じです)。
'var Me = ....'と 'var father = ....'の順番を入れ替えます。 –
私は最後の文を理解していません。どんな特性について私たちは話していますか?ユースケースを提供できますか? – kubetz