-1

この良い例が見つからなかったのはなぜだろうか。関数内では、personはオブジェクトであり、正しい値があり、selectedPersonはグローバル変数です。\ -signsを気にしないでください、それはそれらをここに表示する方法でした。

document.getElementById(heading).innerHTML="<\p><\strong>" + selectedPerson.name+"<strong><\\p>";

これは機能しておらず、HTML内でも機能していません。

<p>
     <strong>
        <script>document.write(selectedPerson.name);</script>
     </strong>
</p>

var selectedPerson;
function person(extra){

var extra_array=extra.split(",");

this.name=extra_array[0];
this.head=extra_array[1];
this.gValue=extra_array[2];
this.weight=extra_array[3];
alert(extra_array[0]+" "+extra_array[1]+" "+extra_array[2] +" "+extra_array[3]);
//alert(this.name" "this.head+" "+extra_array[2] +" "+extra_array[3]);

}

selectedPerson = new person(extra);
    console.log("**************************extra-------------->" +extra);

そして問題は、HTML内でグローバル変数/オブジェクトをどのように使用できるかということです。ある場合は両方の方法を知りたいですか?配列を使用するとアラートは機能しますが、this.nameなどでは機能しません。HTML内で構文selectedPerson.nameを使用するにはどうすればよいですか?

ありがとうございました!サーミ人

4

2 に答える 2

1

でインスタンス化new person()してextraいますundefined

これを実行しようとするとエラーが発生し、メソッドがsplit()ありundefinedませんsplit

オブジェクトの作成に失敗するので、そうselectedPersonなります。undefined

于 2012-07-20T16:29:02.607 に答える
0

宣言する前にグローバル変数を使って書いていると思います。

スクリプトファイルの先頭にある宣言を使用する

于 2012-07-20T16:01:36.767 に答える