Jquery加载div移位
我正在使用以下内容在成功提交 ajax 表单后加载 div。
$('#randomdiv').load('somepage.html #randomdiv');
一切都按照我想要的方式发生,除了当第一次使用按钮触发表单提交时,div 向下移动并在每个方向移动大约 4 个像素。我完全不知道原因是什么。
我正在使用相同的格式重新加载按钮。
$('#submitbutton').load('somepage.html #submitbutton');
该按钮也显示相同的班次。我已经尝试了所有其他刷新方法,但我需要刷新数据库变量,并且此方法是唯一有效的方法。任何帮助将不胜感激。
I am using the following to load a div after a successful ajax form submit.
$('#randomdiv').load('somepage.html #randomdiv');
Everything is happening exactly how I want it to, except that when the button is first used to trigger the form submit, the div shifts down and over about 4 pixels in each directions. I am absolutely stumped to what would be the cause.
I am reloading the button using the same format.
$('#submitbutton').load('somepage.html #submitbutton');
The button is also displaying the same shift. I have tried every other method of refresh, but I am needing to refresh database variables, and this method is the only one that is working. Any help would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您遇到了意外嵌套,表现为视觉偏移。来自精美手册:
因此,当您执行此操作时:
您最终会在 HTML 中得到以下结构:
当您可能期望这样时:
您可能只需要稍微重构 HTML 以获得外部容器元素,例如
#container
,期望将#randomdiv
插入其中:然后执行
$('#container').load('somepage.html #randomdiv')
来放置东西在其中。I think you're getting accidental nesting that is manifesting as a visual offset. From the fine manual:
So when you do this:
You end up with this structure in your HTML:
when you're probably expecting this:
You probably just need to restructure the HTML a bit to have an outer container element, say
#container
, that expects to have#randomdiv
inserted into it:And then do
$('#container').load('somepage.html #randomdiv')
to put things in it.