Javascript.RU

Создать новую тему Ответ
 
Опции темы Искать в теме
  #1 (permalink)  
Старый 21.03.2013, 14:49
Профессор
Отправить личное сообщение для Vasy Посмотреть профиль Найти все сообщения от Vasy
 
Регистрация: 09.02.2013
Сообщений: 165

Верный ответ
Пожалуста подскажите,я понимаю что немогу додумать какуето мелочь но она уже 2 дня в голову не лезет.Есть xml файлик так хранятса ответы вопросы ну и многое другое
<?xml version="1.0" encoding="windows-1251"?>
<?xml-stylesheet href="style.css" type="text/html" ?>

 
<!DOCTYPE test SYSTEM "test.xml">
<test>
<style  border="5px solid black" hight="350px"  width="350px"  padding="20px" margin="0px" position="relative" ></style>
<buttonstyle hight="40px" width="50px" position="fixed" marginleft="150px" ></buttonstyle>
	<attemptsanswer>1</attemptsanswer>
	<questions>
		
		<question>Вопрос</question>
		<answer rating="1"> Да</answer>
		<answer rating="0"> Нет</answer>
	
		<question1>Вопрос1</question1>
		<answer rating="0"> Да</answer>
		<answer rating="1">Нет </answer>
		<textanswer>Да</textanswer>
		<textanswer1>Нет</textanswer1>
	</questions>
		
<attemptext>Вы исчерпали количество попыток</attemptext>	
<attemptext1>Пройдите тест ище раз</attemptext1>	
<TextButton>Ответить на вопрос</TextButton>
<TextButton1>Стереть ответы</TextButton1>
<TextButton2>начать тест заново</TextButton2>
<TextButton3>Получить правильный ответ</TextButton3>
<ResultTextTrue>Ваш ответ верен!</ResultTextTrue>
<ResultTextFalse>Ваш ответ не верен!</ResultTextFalse>
</test>


И есть JS код
<html>

<head>



<meta  charset="utf-8" />
	<title>Test</title>
	
<script type="text/javascript" src="jquery.js"></script>
	

<script type="text/javascript">

						
var answer={}

		$(document).ready(function(){
			$.ajax({
				type: "GET",  
				url: "test.xml", 
				dataType: "xml", 
				success: vasa	
	 			
		});
		
		
		var button2 = document.getElementById("id1");
		button2.style.display='none';
		var button3 = document.getElementById("id3");
		button3.style.display='none';
		
		function vasa(xml) { 
				attemptsanswer=$(xml).find('attemptsanswer').text(); 
				attemptext=$(xml).find('attemptext').text(); 
				attemptext1=$(xml).find('attemptext1').text(); 
					
				 textanswer=$(xml).find('textanswer  ').text();
				$('.cont2').append(''+textanswer+'');
				
				
				 textanswer1=$(xml).find('textanswer1').text();
				$('.cont2').append(''+textanswer1+'');
		        question=$(xml).find('question').text();
				$('.cont1').append('<p><label><h4>'+question+'</h4></label></p>');
				question1=$(xml).find('question1').text();
				$('.bond1').append('<p><label><h4>'+question1+'</h4></label></p>');
				TextButton=$(xml).find('TextButton').text();
				$('.onki').append('<p><label><h4>'+TextButton+'</h4></label></p>');
				TextButton1=$(xml).find('TextButton1').text();
				$('.lolki').append('<p><label><h4>'+TextButton1+'</h4></label></p>');
				TextButton2=$(xml).find('TextButton2').text();
				$('.lolki1').append('<p><label><h4>'+TextButton2+'</h4></label></p>');
				TextButton3=$(xml).find('TextButton3').text();
				$('.lolki2').append('<p><label><h4>'+TextButton3+'</h4></label></p>');
				ResultTextTrue=$(xml).find('ResultTextTrue').text();
				
				ResultTextFalse=$(xml).find('ResultTextFalse').text();
				
		
	answer1=$(xml).find('answer').text();
	
	
				var answers = $(xml).find('answer');
				
 
             		        answers.each(function(index){
									
                            
								
								
                                var rating = +this.getAttribute('rating');
								
									var inputs = document.getElementsByTagName('input');
										if(inputs.length<2)
											{	
											
                                $('.cont').append('<input   name="group1"  type="radio">');
								
								            }
											else
											{
								$('.bond').append('<input   name="group2"  type="radio">');
										   }
                                answer[index] = rating;

				

				
 
                });
				
				
				
				
			
				var div = document.getElementById('id')
				//var decoration = xml.querySelector('style');
				div.style.border = $(xml).find('style').attr('border');
				div.style.width = $(xml).find('style').attr('width'); 
				div.style.height = $(xml).find('style').attr('hight');
				div.style.padding = $(xml).find('style').attr('padding');
				div.style.margin = $(xml).find('style').attr('margin');
				div.style.position = $(xml).find('style').attr('position');
				
				
			//	var p = document.getElementById('id1')
			//	var decoration = xml.querySelector('buttonstyle');
			//	p.style.position = decoration.getAttribute('position');
			//	p.style.width = decoration.getAttribute('width'); 
			//	p.style.height = decoration.getAttribute('hight');
			//	p.style.margin-left = decoration.getAttribute('marginleft');
			//	p.style.margin = decoration.getAttribute('margin');

		}
	
	
	 			
		});
		
		
			
				
	 			
		
			


var pressed=0;
var pressed1=0;		
				function TrueAnswer(){    //Вот эта функция
    
	 var inputs1 = document.getElementsByTagName('input');
            for(var k = 0; k < inputs1.length ; k++){
               
				if(answer[k] == 1){      
			
				
			
            
               
               break;
			   
               }
        }	 
var n=document.getElementById('output');			
         n.value='бла бла бла';                      //просто проверял ёё работу
	}		
function checkAnswer() {
var error = false;
			
					   
            var inputs = document.getElementsByTagName('input');
            for(var i = 0; i < inputs.length ; i++){
               var checked = inputs[i].checked;
              var right = answer[i] == 1;			 			 
               if (checked !== right){
               error=true;
               break;
			   
               }
        }
							
						
					if(pressed<attemptsanswer)
							{
					
					  i = ++pressed;
								
				
                       }
					   else
					   {		
					    
							
							pressed=0;
							var button = document.getElementById("button");
							button.style.display='none';
							var button1 = document.getElementById("id2");
							button1.style.display='none';
							var button2 = document.getElementById("id1");
							button2.style.display='';
							button2.onclick = function(event){	
							
							
							
							button.style.display='';
							button1.style.display='';
							button2.style.display='none';
						
						
						
							
											g=++pressed1;
											
											
											if(pressed1>attemptsanswer)
											{
											button.style.display='none';
											button1.style.display='none';
											button2.style.display='none';
											var button3 = document.getElementById("id3");
											button3.style.display='';
											alert('ваши попытки закончились.Узнайте правильный ответ');
											}
										
										
							
						
							}
			
							
					   }
		var c=document.getElementById('output');			
        c.value=error ? ResultTextFalse : ResultTextTrue;
		
        return false;
					
		
    }
	
	
       
      
       
   

</script>

</head>
<body>


<form  onsubmit="return checkAnswer()">
	
	 
	 

	 <div id="id">	 
	 
	 <div  class='cont2' style="margin-left:156px"></div>
	 
	 
	 <hr>
	
	 <div  class='cont1' ></div>
	

	 <div align="center"   class='cont' ></div>
	
	 <hr> 
	 <div class="bond1"></div>
	 <div align="center" class='bond'></div>
	 <hr>
	
	</div>


	<p style="position:relative"><button id="button" type="submit"  ><div  class='onki'></div></button> <button id="id2" type="reset"><div class='lolki'></div></button><button id="id1" type="reset"><div class='lolki1'></div></button><button id="id3" type="button" onclick="TrueAnswer()" ><div  class='lolki2'></div></button></p>

    <p style=" position:relative"><textarea id="output" readonly></textarea></p>
	
	

	
	 
    

</form>



</body>

</html>


Так вот немогу написать функцию Которая будет выводить только верные ответы(а не все) в текстовое поле. С ID=output.
Я как-бы понимаю что нужно пробегать по всем input узнавать какой ответ верен,но как вывести именно верные ответы там где rating=1 ума не приложу.Подскажите пожалуста.
Ответить с цитированием
  #2 (permalink)  
Старый 21.03.2013, 18:20
Профессор
Отправить личное сообщение для Vasy Посмотреть профиль Найти все сообщения от Vasy
 
Регистрация: 09.02.2013
Сообщений: 165

люди добрые ну подскажите .
Ответить с цитированием
  #3 (permalink)  
Старый 22.03.2013, 16:48
Профессор
Отправить личное сообщение для Vasy Посмотреть профиль Найти все сообщения от Vasy
 
Регистрация: 09.02.2013
Сообщений: 165

Ребят ну подскажите пожалуста
Ответить с цитированием
  #4 (permalink)  
Старый 24.03.2013, 23:05
Аватар для Aetae
Тлен
Отправить личное сообщение для Aetae Посмотреть профиль Найти все сообщения от Aetae
 
Регистрация: 02.01.2010
Сообщений: 6,480

Слишом жуткая каша вместо кода. Даже захотев помочь - плюнул на это дело.

Локализуйте аккуратненько проблему с как можно меньшим кол-вом кода и возможно вам кто-нить поможет.

P.S. Отличная кстати идея как защитить тесты на js от кодеров - писать код настолько отвратительно, чтоб программист решил что пройти тест проще чем копаться в этом дерьме.)
__________________
29375, 35
Ответить с цитированием
Ответ



Опции темы Искать в теме
Искать в теме:

Расширенный поиск


Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
ответ сервера не сохраняется в глобальную переменную cyberpunk AJAX и COMET 2 06.03.2012 11:57
плагин jquery.form (.post) - ответ содержит html тэги, как избавиться? ИванРу AJAX и COMET 2 07.01.2011 10:34
Ответ сервера в плугине ajaxForm отдается неправильно. IgorOk jQuery 11 13.12.2009 04:35
Обратный ответ kotjke AJAX и COMET 2 06.12.2009 16:54
Ajax - JSON - не распознает пришедший ответ Майский Кот jQuery 1 14.05.2009 00:40