Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用javascript更改DIV文本_Javascript_Jquery_Html - Fatal编程技术网

使用javascript更改DIV文本

使用javascript更改DIV文本,javascript,jquery,html,Javascript,Jquery,Html,当在一个div上拖动另一个div时,以下代码会更改该div的背景色。我如何修改它以更改div的文本而不是背景颜色(例如,我将一个div放入其中,其中包含一个Test,我想将拖动到的div更改为Test 代码: 请检查我的JSFIDLE代码,该代码不起作用: 您可以执行以下操作: $(this).html(drag.html()); 代替: $(this).css("background-color", drag.css("background-color")); 你可以做: $(this).

当在一个div上拖动另一个
div
时,以下代码会更改该div的
背景色。我如何修改它以更改div的文本而不是背景颜色(例如,我将一个div放入其中,其中包含一个
Test

,我想将拖动到的div更改为
Test

代码:

请检查我的JSFIDLE代码,该代码不起作用:

您可以执行以下操作:

$(this).html(drag.html());
代替:

$(this).css("background-color", drag.css("background-color"));
你可以做:

$(this).html(drag.html());
代替:

$(this).css("background-color", drag.css("background-color"));
替换

$(this.css(“背景色”),drag.css(“背景色”);

drop.html(drag.html());
替换

$(this.css(“背景色”),drag.css(“背景色”);


drop.html(drag.html());

我知道这不符合SO的精神,但有时我只想尖叫:旁白:既然你缓存了$(这个)作为drop,你应该用drop替换$(这个)的两个实例。我知道这不符合SO的精神,但有时我只想尖叫:旁白:既然你缓存了$(这个)作为drop,您应该替换$(this)的两个实例谢谢你的回答。谢谢你的回答,你能检查我更新的包含JSIDLE链接吗?谢谢你的回答,你能检查我更新的包含JSIDLE链接吗?谢谢你的回答,你能检查我更新的包含JSIDLE链接吗?谢谢你的回答,你能检查我更新的包含JSIDLE链接吗