我正在使用下面的代码,当我点击Link1时,我想要做的事情是它应该自动在pageload上触发事件loadContent,该怎么做?jquery onclick event to change
<head>
<title>jQuery test page</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
function loadContent(elementSelector, sourceUrl) {
$(""+elementSelector+"").load("http://abc.com/"+sourceUrl+"");
}
</script>
</head>
<body>
<a href="javascript:loadContent('#content', 'displayimages.php');">Link 1</a>
<div id="content">content will be loaded here</div>
</body>
</html>
JavaScript事件应该在“onclick”而不是“href”。正确的方法: –