0

このコードに何か問題がありますか?GoogleサイトのHTMLボックスでは機能しません。それが私の問題なのかGoogleの問題なのかわかりません...

ユーザーが入力した名前、性別、性格に応じてテキストをパーソナライズしようとしています。

<script>

function personalize (name, gender, character) {
    var Name = name;

  if (Name !== "") {

    $('.NameComma').html(name + ", ");

    if (character === 'baptist') {

      $('.baptistname').html(name);
    }
    else {
      $('.baptistname').html("");
    }
  }
  else {
    $('.Name').html("");
  }

  if (gender === 'male') {
    $('.mychild').html("My son, ");
  }
  else if (gender === 'female') {
    $('.mychild').html("My daughter, ");
  }
  else {
    $('.mychild').html("");
  }

  if (character === 'baptist') {
    $('.baptist1').html("You");
  }
  else {
    $('.baptist1').html("John the Baptist");
  }

  if (character === 'philip') {
    $('.philip1').html("you");
  }
  else {
    $('.philip1').html("Philip");
  }

  if (character === 'nathanael') {
    $('.nathanael1').html("you");
  }
  else {
    $('.nathanael1').html("Nathanael");
  }
}
</script>

<p><b>Name:</b> <input name="name" type="text" value="" style="position: relative; top:     -4px;" id="namebox" onchange="personalize(document.getElementById('namebox').value,document.getElementById('gender').value,document.getElementById('characterselect').value)"/>
<select name="gender" id="genderselect" onchange="personalize(document.getElementById('namebox').value,document.getElementById('genderselect').value,document.getElementById('characterselect').value)">
  <option id="none" value="none">Select your gender:</option>
  <option id="male" value="male">Male</option>
  <option id="female" value="female">Female</option></select>
<select name="character" id="characterselect" onchange="personalize(document.getElementById('namebox').value,document.getElementById('genderselect').value,document.getElementById('characterselect').value)">
  <option id="none" value="none">Choose your character:</option>
  <option id="baptist" value="baptist">John the Baptist</option>
  <option id="philip" value="philip">Philip</option>
  <option id="nathanael" value="nathanael">Nathanael</option>
  </select>

<span class="baptist1">John the Baptist</span><span class="NameComma"></span><span class="mychild"></span> told <span class="philip1">Philip</span>, who told <span class="nathanael1">Nathanael</span>.
4

1 に答える 1

1

あなたのコードはと呼ばれるドロップダウンを参照してgenderいますが、実際にはgenderselect

最初のonchangeハンドラーを正しいIDに変更します。

onchange="personalize(document.getElementById('namebox').value,document.getElementById('genderselect').value,document.getElementById('characterselect').value)"
于 2012-11-23T22:26:12.350 に答える