gpt4 book ai didi

javascript - 运行按钮点击页面加载

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:57:11 24 4
gpt4 key购买 nike

我有这样的输入“

<input type='button' name='osx' value='Demo' class='osx demo' runat="server" />

当我点击它时,它会运行一个 jQuery 插件。现在我想在我的页面加载时调用这个输入的点击事件,事实上我想在页面加载时运行它的插件,所以我使用这个代码:

<script>
$("document").ready(function () {
window.getElementById("osx").click();
});
</script>

但是当我运行我的页面时,我得到这个错误:

Line: 16 Error: Object doesn't support property or method 'getElementById'

谁能帮帮我,好吗?

我做了你所有的答案,但没有一个对我有用!!!在我页面的代码中:

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<link type='text/css' href='css/osx.css' rel='stylesheet' media='screen' />
<script>
$("document").ready(function () {
document.getElementById("osx").click();
}
</script>
</head>
<body>
<div id='container'>
<div id='content'>
<div id='osx-modal'>
<input id='osx' type='button' name='osx' value='Demo' class='osx demo' runat="server" />
or <a href='#' class='osx'>Demo</a>
</div>
<!-- modal content -->
<div id="osx-modal-content">
<div id="osx-modal-title" dir="rtl">
OSX Style Modal Dialog</div>
<div class="close">
<a href="#" class="simplemodal-close">x</a></div>
<div id="osx-modal-data">
<h2>
Hello! I'm SimpleModal!</h2>
<p>
SimpleModal is a lightweight jQuery Plugin which provides a powerful interface for
modal dialog development. Think of it as a modal dialog framework.</p>
<p>
SimpleModal gives you the flexibility to build whatever you can envision, while
shielding you from related cross-browser issues inherent with UI development..</p>
<p>
As you can see by this example, SimpleModal can be easily configured to behave like
an OSX dialog. With a handful options, 2 custom callbacks and some styling, you
have a visually appealing dialog that is ready to use!</p>
<p>
<button class="simplemodal-close">
Close</button>
<span>(or press ESC or click the overlay)</span></p>
</div>
</div>
</div>
</div>
<script type='text/javascript' src='js/jquery.simplemodal.js'></script>
<script type='text/javascript' src='js/osx.js'></script>
</body>
</html>

我哪里做错了?

最佳答案

<script>
$(document).ready(function () {
document.getElementById("osx").click();
});
</script>

<body onload="document.getElementById('osx').click();">

将 id="osx"添加到您的输入元素

关于javascript - 运行按钮点击页面加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18508262/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com