简体   繁体   English

将click.function()更改为onload

[英]Change click.function() to an onload

I'm using the following script that works fine when I do the click function, but I need to change it so it will happen when the Web page loads. 我使用以下脚本,当我执行click函数时,该脚本可以正常工作,但是我需要对其进行更改,以便在加载网页时发生。 I could not find the answer to my problem searching through stackoverflow, so I would appreciate any help from anyone on how to change it. 我找不到通过stackoverflow搜索问题的答案,因此,感谢任何人提供有关如何更改它的帮助。

<script language="JavaScript">
    $(function() { //run on document.ready
      $("#current_sessioner").click(function() { //this occurs when select 1 changes
        $("#sessioner").val($(this).val());
      });
    });
</script>

Simply move it out of the click handler. 只需将其移出点击处理程序即可。

$(function () {
  $("#sessioner").val($('#current_sessioner').val());
});
document.addEventListener('DOMContentLoaded', function(){
   $("#sessioner").val($('#current_sessioner').val());
}, false);

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

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