Javascript preloader 和 load() 命令的错误

Errors with Javascript preloader and load() command

本文关键字:命令 错误 preloader load Javascript      更新时间:2023-09-26

我正在编写一些按钮的脚本,其onclick命令加载外部html文件并更改图像的src。但是,在浏览器中打开.html文件时,我遇到了我所有的JavaScript代码,以纯简ASCII显示,显然未执行!:(

编辑 修复了"脚本类型"命令的问题。现在,脚本本身似乎根本没有执行。关于可能出现的问题的任何建议?

代码如下:

<script='javascript'>
/*image preloader*/
incompanyImage = new Image(); 
incompanyImage.src = " http://us.123rf.com/400wm/400/400/dotshock/dotshock1211/dotshock121100869/16581370-group-of-happy-young-business-people-in-a-meeting-at-office.jpg"; 
/*alt image 1: http://www.123rf.com/photo_16522931_group-of-happy-young-business-people-in-a-meeting-at-office.html */
/*img source: http://www.123rf.com/photo_16581370_group-of-happy-young-business-people-in-a-meeting-at-office.html */
grupoImage = new Image(); 
grupoImage.src = " http://us.123rf.com/400wm/400/400/dotshock/dotshock1209/dotshock120901786/15403105-business-people-team-group-on-a-meeting-have-success-and-make-deal.jpg";
/*img source: http://www.123rf.com/photo_15403105_business-people-team-group-on-a-meeting-have-success-and-make-deal.html */
/*alt images */
particularImage = new Image(); 
particularImage.src = "http://us.123rf.com/400wm/400/400/auremar/auremar1210/auremar121001327/15672624-concerned-business-associates.jpg";
/*img source: http://www.123rf.com/photo_15672624_concerned-business-associates.html */
/*alt images  */
intensivoImage = new Image();
intensivoImage.src = "http://us.123rf.com/400wm/400/400/dotshock/dotshock1211/dotshock121100861/16581384-group-of-happy-young-business-people-in-a-meeting-at-office.jpg";
/*img source male:  http://www.123rf.com/photo_16580996_portrait-of-a-handsome-young-business-man-on-a-meeting-in-offce-with-colleagues-in-background.html */
/*img source female:  http://www.123rf.com/photo_16581362_business-woman-with-her-staff--people-group-in-background-at-modern-bright-office-indoors.html */
tecnicoImage = new Image();
tecnicoImage.src = "http://us.123rf.com/400wm/400/400/dotshock/dotshock1211/dotshock121100861/16581384-group-of-happy-young-business-people-in-a-meeting-at-office.jpg";
/*img source : http://www.123rf.com/photo_16581384_group-of-happy-young-business-people-in-a-meeting-at-office.html */
/*alt image: */

entrevistaImage = new Image();
entrevistaImage.src = "http://us.123rf.com/400wm/400/400/dotshock/dotshock1211/dotshock121100912/16581362-business-woman-with-her-staff--people-group-in-background-at-modern-bright-office-indoors.jpg";
/* img source: http://www.123rf.com/photo_16581362_business-woman-with-her-staff--people-group-in-background-at-modern-bright-office-indoors.html */
/* alt image (better): http://www.123rf.com/photo_16523034_group-of-happy-young-business-people-in-a-meeting-at-office.html */
/*http://www.123rf.com/photo_16523034_group-of-happy-young-business-people-in-a-meeting-at-office.html */
 
palestraImage = new Image();
palestraImage.src = "http://us.123rf.com/400wm/400/400/dotshock/dotshock1204/dotshock120400224/13112547-young-male-business-man-giving-a-presentation-at-a-meeting-seminar-at-modern-conference-room-on-a-ta.jpg";  
/*img source: http://www.123rf.com/photo_13112547_young-male-business-man-giving-a-presentation-at-a-meeting-seminar-at-modern-conference-room-on-a-ta.html */
 
/*these are the buttons for types of english classes offered*/
functon buttonInCompany()
{
$('#desc').load('incompany.html');
document.images["midimg"].src = incompanyImage.src;
}
functon buttonGrupo()
{
$('#desc').load('grupo.html');
document.images["midimg"].src = grupoImage.src;
}
functon buttonParticular()
{
$('#desc').load('particular.html');
document.images["midimg"].src = particularImage.src;
}
functon buttonIntensivo()
{
$('#desc').load('intensivo.html');
document.images["midimg"].src = intensivoImage.src;
}
function buttonEntrevista()
{
$('desc').load('entrevista.html');
document.images["midimg"].src = entrevista.html;    
}    
functon buttonTecnico()
{
$('#desc').load('tecnico.html');
document.images["midimg"].src = tecnicoImage.src;
}
function buttonPalestra()
{
$('#desc').load('palestra.html');
document.images["midimg"].src = palestraImage.src;
}
</script>

现在是 HTML。

<div>
    <p style="text-align: center;"><img name="midimg" width="233" height="350"  class="art-lightbox" src="images/Fotolia_5170186_X-01.jpg"><br></p>
</div>
<div>
    <p class="desc" name="desc">hasdf</p>
</div>
  <div class="art-button" onClick:"buttonParticular()">Aulas Particulares</div>
  <div class="art-button" onClick:"buttonGrupo()">Aulas em Grupo</div>
  <div class="art-button" onClick:"buttonInCompany()">Aulas in-Company</div>
  <div class="art-button" onClick:"buttonIntensivo()">Aulas Intensivos</div>
  <div class="art-button" onClick:"buttonEntrevista()">Aulas para Entrevista</div>
  <div class="art-button" onClick:"buttonTecnico()"> Aulas sobre sua Area</div>
  <div class="art-button" onClick:"buttonPalestra()">Palestras</div>

我做错了什么?

问题(正如其他人所评论的那样,但没有作为答案发布)是你的开场<script='javascript'>。您正在寻找:

<script type='text/javascript'>

另外:您的一些function声明拼写错误为"functon"

您应该用=而不是:来遵循onclick

<div onclick="...">

只需将<script='javascript'>更改为<script type='javascript'>即可。由于浏览后没有空间script所以会得到一个名为script='javascript'(它不熟悉)的标签而不是script

也:

<div class="art-button" onClick:"buttonParticular()">Aulas Particulares</div>

应该是

<div class="art-button" onClick="buttonParticular()">Aulas Particulares</div>

html 中,您应该在属性名称(在您的情况下onclick)和值 ( "buttonParticular()" ) 之间放置=