2013-09-23 5 views
-1

Моя страница загружается с фоном, затем я нажимаю на ссылку, и это дает мне мой javascript, как ожидалось, но как только он заканчивает и выводит результаты, он переходит на пустой белый экран с моими результатами , Я хочу, чтобы результаты отображались на моей веб-странице с фоном. Я пробовал и пытался безрезультатно. Вот мой код:Javascript продолжает скрывать мой веб-фон

<!doctype html> 
<html> 
<head> 
<meta charset="utf-8"> 
<title>Untitled Document</title> 
<script type="text/javascript"> 
function myFunction() 
{ 

var accountnum; 
var beginningBal; 
var itemsCharged; 
var credits; 
var creditLimit; 
var sum; 

accountnum = window.prompt("Enter the account number:"); 

beginningBal = window.prompt("Enter the beginning balance:"); 

itemsCharged = window.prompt("Total of all items charged:"); 

credits = window.prompt("Total credits applied to this account:"); 

creditLimit = window.prompt("Enter the credit limit: "); 

var zero = parseInt (accountnum); 
var first = parseInt(beginningBal); 
var second = parseInt(itemsCharged); 
var third = parseInt (credits); 
var fourth = parseInt (creditLimit); 
var sum = first + second - third; 
var diff = fourth - sum; 
if (sum < fourth) 
{ 
    document.writeln("<h1>Your account number is:" + zero); 
    document.writeln("<h1>Your beginning balance is: $" + first); 
    document.writeln("<h1>Total of items charged: $" + second); 
    document.writeln("<h1>Total credits applies to this account: $" + third); 
    document.writeln("<h1>Your credit limit is: $" + fourth); 
    document.writeln("<h1>Your account balance is: $" + sum); 
    document.writeln("<h1>Your credit is: $" + diff); 
    document.getElementById('output').innerHTML = html; 

} 
else if (sum > fourth) 
{ 
    document.writeln("<h1>Your account number is:" + zero); 
    document.writeln("<h1>Your beginning balance is: $" + first); 
    document.writeln("<h1>Total of items charged: $" + second); 
    document.writeln("<h1>Total credits applies to this account: $" + third); 
    document.writeln("<h1>Your new account balance is: $" + sum); 
    document.writeln("<h1>Your credit limit is: $" + fourth); 
    document.writeln("<h1>Your new balance is: $" + diff); 
    document.writeln("<h1>Your credit is exceeded!"); 
    document.getElementById('output').innerHTML = html; 
} 
else if (sum == fourth) 
{ 
    document.writeln("<h1>Your account number is:" + zero); 
    document.writeln("<h1>Your beginning balance is: $" + first); 
    document.writeln("<h1>Total of items charged: $" + second); 
    document.writeln("<h1>Total credits applies to this account: $" + third); 
    document.writeln("<h1>Your account balance is: $" + sum); 
    document.writeln("<h1>Your credit limit is: $" + fourth); 
    document.writeln("<h1>Your new balance is: $" + diff); 
    document.writeln("<h1>You are out of credit!"); 
    document.getElementById('output').innerHTML = html; 
} 
} 

</script> 
<style> 
#output{ 
    height:43px; 

} 
html{ 
    background: url(images/nxerainbowgrid.jpg) no-repeat center center fixed; 
    z-index:-9999; 
    -webkit-background-size: cover; 
    -moz-background-size: cover; 
    -o-background-size: cover; 
    background-size: cover; 
    filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='images/nxerainbowgrid.jpg', sizingMethod='scale'); 
-ms-filter: "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='images/nxerainbowgrid.jpg', sizingMethod='scale')"; 
} 
</style> 
</head> 

<body> 
<a href="#" onClick="myFunction()"><p>CLICK HERE TO HAVE FUN!!!</p></a> 
<div id="output"></div> 
</body> 
</html> 
+1

JSfiddle будет полезен для нас – Rich

ответ

1

Хотя это не лучший способ. или правильный путь. Вы не должны повторять много кода. и используйте подсказку. Следующим может быть временное решение

Определить html, а также изменить стиль ccs на тело. в таком случае. Фоновое изображение будет aplly в теле страницы

var html; 
if(sum<forth){ 
    html ="<h1> Your account number is:" + zero + "</h1>"; 
    html ="<h1>Your beginning balance is: $" + first + "</h1>"; 
    html ="<h1>Total of items charged: $" + second + "</h1>"; 
    html ="<h1>Total credits applies to this account: $" + third + "</h1>"; 
    html ="<h1>Your credit limit is: $" + fourth + "</h1>"; 
    html ="<h1>Your account balance is: $" + sum + "</h1>"; 
    html ="<h1>Your credit is: $" + diff + "</h1>"; 
    document.getElementById('output').innerHTML = html; 
}  


body{ 
    background: url(index.jpeg) no-repeat center center fixed; 
    /*keep all other. only change the tag name*/ 
} 
+0

Постараюсь это. дай мне минуту. –

+0

Возможно, я не понимаю, что вы поставили: document.getElementById ('output'). InnerHTML = "

My Dom

"; Я не понимаю, что вы подразумеваете под

My Dom

+0

У вас есть набор входных данных. для каждого шага. Я помещаю номер и вижу результат. В вашем случае вы видите фоновое изображение. – KhanSharp

Смежные вопросы