我可以从javascript中获取结果并将其传递给我的主.NET aspx数据库吗? [英] Can I take a result from javascript and pass it to my main .NET aspx database?

查看:69
本文介绍了我可以从javascript中获取结果并将其传递给我的主.NET aspx数据库吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello。我必须使用Visual Studio .NET ASP创建一个Web应用程序。我用javascript进行一些测验。现在我想获取测验的RESULT值并将其存储到我的数据库..

怎么可能?

下面是我的脚本。

从那个脚本我想取最终得分值并保存到我的数据库。 />


我的尝试:



  var 得分=  0 ;  //  将分数设为0  
var total = 5 ; // 问题总数
var point = 2 ; // 每个正确答案的点数
var 最高=总*点;



// 初始化程序
function init(){
// 设置正确的答案
sessionStorage.setItem(' a1'' c');
sessionStorage.setItem(' a2' ' c');
sessionStorage.setItem(' a3' ' a');
sessionStorage.setItem(' a4' ' c');
sessionStorage.setItem(' a5' ' a');
}

$( document )。ready( function ( ){
// 隐藏所有问题
$(' 。questionForm')。hide();

// 显示第一个问题
$(' #q1')。show();

$(' 。questionForm #submit')。click( function (){
// 获取数据属性
current = $( this )。parents(' form:first')。data(' 问题');
ne xt = $( this )。parents(' 表单:第一个')。data(' question')+ 1;
// 隐藏所有问题
$(' 。questionForm')。hide();
// 显示下一个问题
$(' #q' + next + ' ')。fadeIn( 300 );
process(' ' + current + ' ');
return false ;
});
});

// 处理答案
function process(n){
// 获取输入值
var submitted = $(' 输入[name = q' + n + ' ]:选中')。val() ;
if (submitted == sessionStorage.getItem(' a' + n + ' ')){
得分=得分+点;
}

if (n == total){
$(' #results')。html(' < h3>您的最终得分是:' +得分+ ' out of' +最高+ ' < / h3>< a href =EnglishTest1.aspx>再次进行测验< / a> ;');
if (得分==最高){
$(' #results')。append(' < p>你是一个英语大师!');
} 其他 如果(得分==最高 - 点数||得分==最高点数 - 点){
$(' #results')。append(' < p> Good Job!');
}
其他 {
$(' #results')。append(' < p>你还没学习够了。学习并稍后回来!');
}
}
返回 false ;
}




// 添加事件侦听器
window .addEventListener(' load',init, false );

解决方案

document )。ready( function (){
// 隐藏所有问题


' 。questionForm')。hide();

// 显示第一个问题


' #Q1' )表示();

Hello.I have to make a web application with Visual Studio .NET ASP.I make some quiz with javascript.Now i want to take the RESULT value of the quiz and store it to my Database..
How is it possible?
Below there is my script.
From that script i want to take the final score value and save it to my database.

What I have tried:

var score = 0; //Set score to 0
var total = 5; //Total number of questions
var point = 2; //Points per correct answer
var highest = total * point;



//Initializer
function init(){
	//set correct answers
	sessionStorage.setItem('a1','c');
	sessionStorage.setItem('a2','c');
	sessionStorage.setItem('a3','a');
	sessionStorage.setItem('a4','c');
	sessionStorage.setItem('a5','a');
}

$(document).ready(function(){
	//Hide all questions
	$('.questionForm').hide();
	
	//Show first question
	$('#q1').show();
	
	$('.questionForm #submit').click(function(){
		//Get data attributes
		current = $(this).parents('form:first').data('question');
		next = $(this).parents('form:first').data('question')+1;
		//Hide all questions
		$('.questionForm').hide();
		//Show next question
		$('#q'+next+'').fadeIn(300);
		process(''+current+'');
		return false;
	});
});

//Process the answers
function process(n){
	//Get input value
	var submitted = $('input[name=q'+n+']:checked').val();
	if(submitted == sessionStorage.getItem('a'+n+'')){
			score = score + point;
	}
		
	if(n == total){	
		$('#results').html('<h3>Your final score is: '+score+' out of '+highest+'</h3><a href="EnglishTest1.aspx">Take Quiz Again</a>');
		if(score == highest){
			$('#results').append('<p>You are an Enghlish master!');
		} else if(score == highest - point || score == highest - point - point){
			$('#results').append('<p>Good Job!');
		}
		 else  {
            $('#results').append('<p>You have not study enough.Study and come back later !');
        }
	}
	return false;
}




//Add event listener
window.addEventListener('load',init,false);

解决方案

(document).ready(function(){ //Hide all questions


('.questionForm').hide(); //Show first question


('#q1').show();


这篇关于我可以从javascript中获取结果并将其传递给我的主.NET aspx数据库吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆