2012-11-23 17 views
0

此代碼有問題嗎?它不是在谷歌網站HTML框工作,我不知道這是我的問題還是谷歌的...個性化具有三個值(名稱,性別和字符)的敘述文本

我只是試圖根據用戶輸入的名稱,性別和字符來個性化文本。

<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>. 
+0

什麼不起作用?你有任何錯誤? –

回答

1

你的代碼引用了一個名爲gender下拉列表中,但它實際上是所謂genderselect

你的第一個onChange處理更改爲正確的ID。

onchange="personalize(document.getElementById('namebox').value,document.getElementById('genderselect').value,document.getElementById('characterselect').value)" 
+0

謝謝布蘭登!愚蠢的錯誤。 –

相關問題