代码适用于HTML 4.0 Transitional DOCTYPE,但不适用于XHTML 1.0 Transitional [英] Code works with HTML 4.0 Transitional DOCTYPE, but not with XHTML 1.0 Transitional

查看:70
本文介绍了代码适用于HTML 4.0 Transitional DOCTYPE,但不适用于XHTML 1.0 Transitional的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有这样的脚本


[HTML]

<!DOCTYPE HTML PUBLIC" - // W3C // DTD HTML 4.0 Transitional // EN">

< html>

< head>

< title> Drag&Drop< / title>

< style>

#slater {

display:block;

宽度:13px;

身高:22px;

背景:url(slater.gif);

光标:指针;

position:relative;

border:0px;

}

#main_box {

position:relative;

宽度:113px;

身高:22px;

背景:url(background_slate.jpg)无重复;

border:0px;

}

< / style>

< script>


if(navigator.appName ==" Microsoft Internet Explorer){var Browser =" IE" ;; } else {var Browser =" FF" ;; }

var MoveIT ="" ;;


函数startDrag(){

OffsetX = MouseX - (document.getElementById (''slater'')。style.left).rep lace(" px","");

MoveIT =" yes";

}


函数mouseMoveFF(事件){

MouseX = event.clientX;

if(MoveIT ==" yes" ){

document.getElementById(''slater'')。style.left = MouseX - OffsetX;


if(document.getElementById(''slater) '')。style.left.re place(" px","")< = 0){

document.getElementById(''slater'')。style.left = 0 +" px";

}否则if((document.getElementById(''slater'')。style.left.rep lace(" px",""))> ; = 100){

document.getElementById(''slater'')。style.left = 100 +" px";

}


var speed = document.getElementById(''slater'')。style.left.repla ce(" px","")/ 10;

var fix_pt =(document.getElementById(''slater) '')。style.left!=" 0pt")?速度:''0';

document.getElementById(''速度'')。innerHTML = fix_pt;

}

}


函数mouseMoveIE(){

MouseX = event.clientX;

if(MoveIT ==" yes"){

document.getElementById(''slater'')。style.left = MouseX - OffsetX;


if(document.getElementById(''slater'') .style.left.re place(" px","")< = 0){

document.getElementById(''slater'')。style.left = 0 +" ; px" ;;

}否则if((document.getElementById(''slater'')。style.left.rep lace(" px",""))> = 100 ){

document.getElementById(''slater'')。style.left = 100 +" px";

}


var speed = document.getElementById(''slater'')。style.left.repla ce(" px","")/ 10;

document.getElementB yId(''speed'')。innerHTML = speed;

}

}


if(Browser ==" IE"){document.onmousemove = mouseMoveIE; } else {document.onmousemove = mouseMoveFF; }

document.onmouseup = function(){MoveIT ="" ;; }


< / script>

< / head>

< body>

< div id =" main_box">

< div id =" slater" onMouseDown =" startDrag()">< / div>

< / div>

< div id =" speed" style =" font-family:Arial,Helvetica,sans-serif;字体大小:10px的;颜色:#666666;"> 0< / div>

< / body>

< / html>

[/ HTML]

所以它工作文件,但这是我的问题它是在<!DOCTYPE HTML PUBLIC" - // W3C // DTD HTML 4.0 Transitional // EN"> HTML 4.0 Transitional我需要它是<!DOCTYPE html PUBLIC" - // W3C // DTD XHTML 1.0 Transitional // EN" " HTTP://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">但这是我的问题当我改变HTML 4.0 Transitional到XHTML 1.0 Transitional它停止工作所以可以有人告诉我如何让我的脚本使用XHTML 1.0 Transitional(在即XHTML 1.0 Transitional工作但不在FF上)

so i got script like that

[HTML]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Drag and Drop</title>
<style>
#slater {
display:block;
width:13px;
height:22px;
background:url(slater.gif);
cursor:pointer;
position:relative;
border:0px;
}
#main_box {
position:relative;
width:113px;
height:22px;
background:url(background_slate.jpg) no-repeat;
border:0px;
}
</style>
<script>

if (navigator.appName == "Microsoft Internet Explorer") { var Browser = "IE"; } else { var Browser = "FF"; }
var MoveIT = "";

function startDrag() {
OffsetX = MouseX - (document.getElementById(''slater'').style.left).rep lace("px","");
MoveIT = "yes";
}

function mouseMoveFF(event) {
MouseX = event.clientX;
if (MoveIT == "yes") {
document.getElementById(''slater'').style.left = MouseX - OffsetX;

if(document.getElementById(''slater'').style.left.re place("px","") <= 0) {
document.getElementById(''slater'').style.left = 0+"px";
} else if ((document.getElementById(''slater'').style.left.rep lace("px","")) >= 100) {
document.getElementById(''slater'').style.left = 100+"px";
}

var speed = document.getElementById(''slater'').style.left.repla ce("px","") / 10;
var fix_pt = (document.getElementById(''slater'').style.left != "0pt") ? speed : ''0'';
document.getElementById(''speed'').innerHTML = fix_pt;
}
}

function mouseMoveIE() {
MouseX = event.clientX;
if (MoveIT == "yes") {
document.getElementById(''slater'').style.left = MouseX - OffsetX;

if(document.getElementById(''slater'').style.left.re place("px","") <= 0) {
document.getElementById(''slater'').style.left = 0+"px";
} else if ((document.getElementById(''slater'').style.left.rep lace("px","")) >= 100) {
document.getElementById(''slater'').style.left = 100+"px";
}

var speed = document.getElementById(''slater'').style.left.repla ce("px","") / 10;
document.getElementById(''speed'').innerHTML = speed;
}
}

if (Browser == "IE") { document.onmousemove = mouseMoveIE; } else { document.onmousemove = mouseMoveFF; }
document.onmouseup = function () { MoveIT = ""; }

</script>
</head>
<body>

<div id="main_box">
<div id="slater" onMouseDown="startDrag()"></div>
</div>
<div id="speed" style="font-family:Arial, Helvetica, sans-serif; font-size:10px; color:#666666;">0</div>
</body>
</html>
[/HTML]
so it works file but this is my problem it''s made on <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> HTML 4.0 Transitional i need it to be <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> but this i my problem when i change HTML 4.0 Transitional to XHTML 1.0 Transitional it stops working so can some one tell me how to make my script work with XHTML 1.0 Transitional (on ie XHTML 1.0 Transitional works but not on FF)

推荐答案

从html中取出脚本并使用

< script type =" text / javascript"链接到它SRC =>< /脚本>在头部,并在头部包含一个标题元素。

将事件分配放在远程脚本的onload调用中。
Take the script out of the html and link to it with
<script type="text/javascript" src=></script> in the head, and include a title element in the head.
put the event assignment in an onload call in the remote script.


我确实喜欢这个和它仍然无法工作

[HTML]

<!DOCTYPE html PUBLIC" - // W3C // DTD XHTML 1.0 Transitional // EN" http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

< html xmlns =" http://www.w3.org / 1999 / xhtml">

< head>


< meta http-equiv =" Content-Type"含量=" text / html的;字符集=窗户-1257" />

< title> Drag< / title>

< script type =" text / javascript"语言= QUOT; JavaScript的" src =" script.js">< / script>

< link type =" text / css"的rel ="样式表" HREF =" css.css" />


< / head>

< body>

< div id =" main_box"> ;

< div id =" slater" onMouseDown =" startDrag()">< / div>

< / div>

< div id =" speed"> 0< / div>

< / body>

< / html>

[/ HTML]


现在有什么想法可以做吗?

但是在它工作
i did like this and it still not working
[HTML]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<meta http-equiv="Content-Type" content="text/html; charset=windows-1257" />
<title>Drag</title>
<script type="text/javascript" language="javascript" src="script.js"></script>
<link type="text/css" rel="stylesheet" href="css.css" />

</head>
<body>
<div id="main_box">
<div id="slater" onMouseDown="startDrag()"></div>
</div>
<div id="speed">0</div>
</body>
</html>
[/HTML]

have any ideas hat to do now??
but on ie it works


onload不工作或者我不能正确使用它你是否可以告诉我如何使用它?
onload is not working or ma bey im not using it right can you tell me how to use it???


这篇关于代码适用于HTML 4.0 Transitional DOCTYPE,但不适用于XHTML 1.0 Transitional的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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