拖放按钮后更改样式div [英] change style div after dragdrop by button
本文介绍了拖放按钮后更改样式div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个div和一个按钮.将这个div对象拖放到其他位置之后.我希望当我单击按钮时,该div对象将随着新位置的改变而改变样式.我已经处理过拖放操作.
Div对象已更改位置:
I have a div and a button. After drag&drop this div object to other position. I want that when I click button, that div object will change style with new position has just changed. I have already processed drag&drop.
Div object changed postion:
<div id="divml5" class="dragDiv1" runat="server" style="width:40px;height:40px;position:relative;
left:120px;top:60px;">
<table>
<tr>
<td>
<h5 id="h5ml5" class="handler" runat="server"
style="background-image:url('../../Images/image.jpg');
vertical-align:middle;width:40px; height:40px;background-repeat:no-repeat;"></h5>
</td>
</tr>
</table>
</div>
按钮
Button
<button type="button" id="btn" runat="server" onclick="changeStyle();">ChangeStyle</button>
并且我有paragrahp代码来处理该div对象的更改样式:
and I have paragrahp code to process change style of that div object:
var divml5 = document.getElementById("divml5");
var h5ml5 = document.getElementById("h5ml5");
function changeStyle(){
divml5.style.backgroundImage = "url('../Images/clientRed.jpg')";
h5ml5.style.backgroundImage = "url('../Images/clientRed.jpg')";
我想我可以实现所需的功能,但是无法处理.
I think I can implement as I want, but it can''t process.
推荐答案
您尝试使用onClick吗? (注意大写字母C).
如果仍然无法使用,则可能是因为您的按钮具有runat ="server",当您单击它时将进行回发.使用
Did you try onClick instead? (Notice the capital C).
If it still does not work it could be since your button has runat="server" it will do a postback when you click it. Either use
onClick="changeStyle();return false"
防止重新提交,或者不使用runat ="server".
to prevent resubmit or do not use runat="server".
您是否检查过JavaScript是否正确?还是背景图片URL是否正确?
Have you checked if your javascript is correct? or whether the background image URL is correct?
这篇关于拖放按钮后更改样式div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文