【发布时间】:2011-07-06 12:04:06
【问题描述】:
如何使用外部 js 文件访问或获取表单内元素的 div id?
这是一个例子 asp文件
<html>
<head>
<script src="jquery.js"></script>
<script src="jsqueryms.js></script>
<script src="myjs.js"></script>
<body onload="initmyjs();">
<form id="formid">
<input type="button" id="button"/>
<div id='dialog'>this is modal dialog</dialog>
</form>
</head>
</html>
外部js文件
function initmyjs()
{
if document.getelementby('button')!=null
{
document.getelementbyid('button').onlclick=function()
{
$('#dialog').dialog({ modal: true, position: [902, 345], width: 400 });
}
}
}
我想要的是在单击按钮后弹出一个模式对话框,如果脚本位于 asp 页面内,我可以毫无问题地访问它,但如果我将它放在外部 js 文件中,则没有任何反应,但不会显示脚本错误。我想知道脚本是否正确,除了我无法映射我的 div 的正确元素 id。提前谢谢你。
【问题讨论】:
标签: jquery-selectors