html想实现iframe 内DIV任意拖动
<body><selectid="FontSize"class="TBGen"onChange="format('fontsize',this[this.selected...
<body>
<select id="FontSize" class="TBGen" onChange="format('fontsize',this[this.selectedIndex].value);this.selectedIndex=0">
<option selected>字号</option>
<option value="7">一号</option>
<option value="6">二号</option>
<option value="5">三号</option>
<option value="4">四号</option>
<option value="3">五号</option>
<option value="2">六号</option>
<option value="1">七号</option>
</select>
<input type="button" value="字体颜色" LANGUAGE="javascript" onClick="foreColor()" />
</div>
<br />
<input type="button" value="下划线" LANGUAGE="javascript" onClick="format('underline')" />
<input type="button" value="上标" LANGUAGE="javascript" onClick="format('superscript')" />
<input type="button" value="下标" LANGUAGE="javascript" onClick="format('subscript')" />
<input type="button" value="加粗" LANGUAGE="javascript" onClick="format('bold')" />
<input type="button" value="单删除线" LANGUAGE="javascript" onClick="format('strikethrough')"/><br/>
<input id="EditMode" onClick="xuanze()" type="button" value="添加选择项" />
<input type="hidden" id="innerHTMLs" name="innerHTMLs" />
<input type="button" onclick="names()" value="姓名" />
<input type="submit" onclick="cleanHtml()" value="确定"/>
<br />
<iframe class="HtmlEdit" id="HtmlEdit" width="700" height="800" style=""> </iframe>
</body>
<script language=javascript>
HtmlEdit.document.open(); //打开一个文档用于收集 write 、 writeln 方法的输出
HtmlEdit.document.close();
HtmlEdit.document.designMode="On";
function format(what,opt){ //选择格式
if (opt=="removeFormat")
{
what=opt;
opt=null;
}
if (opt==null) HtmlEdit.document.execCommand(what);
else HtmlEdit.document.execCommand(what,"",opt);
HtmlEdit.focus();
}
function foreColor() { //选择字体颜色调用selcolor.html
var arr = showModalDialog("selcolor.html", "", "dialogWidth:18.5em; dialogHeight:17.5em; status:0");
if (arr != null) format('forecolor', arr);
else HtmlEdit.focus();
}
function cleanHtml() //显示html代码
{
document.getElementById("innerHTMLs").value=HtmlEdit.document.body.innerHTML;
alert(document.getElementById("innerHTMLs").value);
}
function xuanze(){
HtmlEdit.focus();
var range = HtmlEdit.document.selection.createRange();
var arr = showModalDialog("xuanze.html", "", "dialogWidth:300pt;dialogHeight:236pt;help:0;status:0");
range.pasteHTML(arr);
HtmlEdit.focus();
}
function names(){
HtmlEdit.focus();
var range = HtmlEdit.document.selection.createRange();
range.pasteHTML('<div id="apDiv1" style="position:absolute; width:203px; height:28px; z-index:1;">姓名:<%=sadas%></div>');
HtmlEdit.focus();
}
</script> 展开
<select id="FontSize" class="TBGen" onChange="format('fontsize',this[this.selectedIndex].value);this.selectedIndex=0">
<option selected>字号</option>
<option value="7">一号</option>
<option value="6">二号</option>
<option value="5">三号</option>
<option value="4">四号</option>
<option value="3">五号</option>
<option value="2">六号</option>
<option value="1">七号</option>
</select>
<input type="button" value="字体颜色" LANGUAGE="javascript" onClick="foreColor()" />
</div>
<br />
<input type="button" value="下划线" LANGUAGE="javascript" onClick="format('underline')" />
<input type="button" value="上标" LANGUAGE="javascript" onClick="format('superscript')" />
<input type="button" value="下标" LANGUAGE="javascript" onClick="format('subscript')" />
<input type="button" value="加粗" LANGUAGE="javascript" onClick="format('bold')" />
<input type="button" value="单删除线" LANGUAGE="javascript" onClick="format('strikethrough')"/><br/>
<input id="EditMode" onClick="xuanze()" type="button" value="添加选择项" />
<input type="hidden" id="innerHTMLs" name="innerHTMLs" />
<input type="button" onclick="names()" value="姓名" />
<input type="submit" onclick="cleanHtml()" value="确定"/>
<br />
<iframe class="HtmlEdit" id="HtmlEdit" width="700" height="800" style=""> </iframe>
</body>
<script language=javascript>
HtmlEdit.document.open(); //打开一个文档用于收集 write 、 writeln 方法的输出
HtmlEdit.document.close();
HtmlEdit.document.designMode="On";
function format(what,opt){ //选择格式
if (opt=="removeFormat")
{
what=opt;
opt=null;
}
if (opt==null) HtmlEdit.document.execCommand(what);
else HtmlEdit.document.execCommand(what,"",opt);
HtmlEdit.focus();
}
function foreColor() { //选择字体颜色调用selcolor.html
var arr = showModalDialog("selcolor.html", "", "dialogWidth:18.5em; dialogHeight:17.5em; status:0");
if (arr != null) format('forecolor', arr);
else HtmlEdit.focus();
}
function cleanHtml() //显示html代码
{
document.getElementById("innerHTMLs").value=HtmlEdit.document.body.innerHTML;
alert(document.getElementById("innerHTMLs").value);
}
function xuanze(){
HtmlEdit.focus();
var range = HtmlEdit.document.selection.createRange();
var arr = showModalDialog("xuanze.html", "", "dialogWidth:300pt;dialogHeight:236pt;help:0;status:0");
range.pasteHTML(arr);
HtmlEdit.focus();
}
function names(){
HtmlEdit.focus();
var range = HtmlEdit.document.selection.createRange();
range.pasteHTML('<div id="apDiv1" style="position:absolute; width:203px; height:28px; z-index:1;">姓名:<%=sadas%></div>');
HtmlEdit.focus();
}
</script> 展开
展开全部
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>jQuery 模块拖动,拖动层效果</title>
<style type="text/css">
#div2
{
position:absolute;
width:400px;
height:300px;
border:1px solid #333333;
background-color:#777788;
text-align:center;
line-height:400%;
font-size:13px;
left:80px;
top:20px;
}
</style>
<script type="text/javascript" language="javascript"
src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript" language="javascript">
var _move=false;//移动标记
var _x,_y;//鼠标离控件左上角的相对位置
$(document).ready(function(){
$("#div2").click(function(){
//alert("click");//点击(松开后触发)
}).mousedown(function(e){
_move=true;
_x=e.pageX-parseInt($("#div2").css("left"));
_y=e.pageY-parseInt($("#div2").css("top"));
$("#div2").fadeTo(20, 0.25);//点击后开始拖动并透明显示
});
$(document).mousemove(function(e){
if(_move){
var x=e.pageX-_x;//移动时根据鼠标位置计算控件左上角的绝对位置
var y=e.pageY-_y;
$("#div2").css({top:y,left:x});//控件新位置
}
}).mouseup(function(){
_move=false;
$("#div2").fadeTo("fast", 1);//松开鼠标后停止移动并恢复成不透明
});
});
</script>
</head>
<body>
<div id="div2">支持拖拽</div>
</body>
</html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>jQuery 模块拖动,拖动层效果</title>
<style type="text/css">
#div2
{
position:absolute;
width:400px;
height:300px;
border:1px solid #333333;
background-color:#777788;
text-align:center;
line-height:400%;
font-size:13px;
left:80px;
top:20px;
}
</style>
<script type="text/javascript" language="javascript"
src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript" language="javascript">
var _move=false;//移动标记
var _x,_y;//鼠标离控件左上角的相对位置
$(document).ready(function(){
$("#div2").click(function(){
//alert("click");//点击(松开后触发)
}).mousedown(function(e){
_move=true;
_x=e.pageX-parseInt($("#div2").css("left"));
_y=e.pageY-parseInt($("#div2").css("top"));
$("#div2").fadeTo(20, 0.25);//点击后开始拖动并透明显示
});
$(document).mousemove(function(e){
if(_move){
var x=e.pageX-_x;//移动时根据鼠标位置计算控件左上角的绝对位置
var y=e.pageY-_y;
$("#div2").css({top:y,left:x});//控件新位置
}
}).mouseup(function(){
_move=false;
$("#div2").fadeTo("fast", 1);//松开鼠标后停止移动并恢复成不透明
});
});
</script>
</head>
<body>
<div id="div2">支持拖拽</div>
</body>
</html>
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询