次のページがあります。
<html>
<head>
<title>Test</title>
<script type="text/javascript">
function BuildTree() {
var total = 0;
var pages = document.getElementsByTagName('custom:page');
var questions = pages[0].getElementsByTagName('custom:question');
for (var i = 0; i < questions.length; ++i) {
var question = questions[i];
var val = question.getAttribute('value')
total += val;
}
alert("Total: " + total);
};
</script>
</head>
<body>
<custom:pages>
<custom:page>
<custom:question value="1">aaa</custom:question>
<custom:question value="2">bbb</custom:question>
<custom:question value="3">ccc</custom:question>
</custom:page>
<custom:page>
<custom:question value="1">aaa</custom:question>
<custom:question value="2">bbb</custom:question>
<custom:question value="3">ccc</custom:question>
</custom:page>
</custom:pages>
<input id="btnTest" type="button" value="Test" onclick="BuildTree();" />
</body>
</html>
IE で [テスト] ボタンをクリックすると結果は 0 になり、FF でクリックすると結果は 0123 になります。
両方のブラウザで同じ結果を得るにはどうすればよいですか? つまり、「0123」です。
これを可能な限り単純な例に切り詰めたことに注意してください。jquery やサードパーティのライブラリは使用できません。純粋な Javasscript ソリューションが必要です。custom: タグも変更できません。
ありがとう