【发布时间】:2014-12-23 14:02:17
【问题描述】:
我遇到了以下问题。每次用户单击锚点时,我都需要设置一个 div 的宽度。此 div 的宽度应取自另一个 div。如何做到这一点?
以下代码不起作用(请记住,该脚本包含在 PHP echo 中):
jQuery(".geother").click(function(){
var pos=$("p.second").width() + "px";
jQuery("#headerRightContactPhone span").css(\'width\', pos);
}
编辑(我还需要另外的东西,我想应用到“geother” div CSS left,这将是 pos width+230px 的负值):
jQuery(".geother").click(function(){
var pos = $("p.second").width(); // don't need to use 'px'
jQuery("#headerRightContactPhone span").css('width', pos); // don't need escaping
$(this).css('left', ((230+pos)*-1) );
});
【问题讨论】:
-
我从来没有使用过 span;应该在几年内被弃用,我希望......