简体   繁体   English

服务器端调用后如何在div load上调用javascript函数?

[英]How to call a javascript function on div load after server side call?

I have a form and once it gets submitted successfully , then after the roundtrip from the server I get a success message displayed on the same page. 我有一个表单,一旦成功提交,然后从服务器往返后,我得到一个成功的消息显示在同一页面上。

I am using the following code: 我使用以下代码:

<s:if test="%{#session.str==1}" >
<div onload="showSuccessToast();">
  <button onclick="showSuccessToast();"></button>
</div>
</s:if>

Now when I return from the server (form submit successful) then the button is displayed and on its onClick event the showSuccessToast() is called but when I expect div to call this function on the onload event it has no effect. 现在当我从服务器返回时(表单提交成功)然后显示按钮,并在其onClick事件上调用showSuccessToast() ,但是当我希望div在onload事件上调用此函数时它没有任何效果。

Any idea how to achieve this. 任何想法如何实现这一点。

Modify it as follows which is kind of simulating "on-load-div": 修改如下,这是一种模拟“on-load-div”:

<s:if test="%{#session.str==1}" >
<div>
  <button onclick="showSuccessToast();"></button>
  <script language="javascript" type="text/javascript">
      showSuccessToast();
  </script>
</div>
</s:if>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM