【发布时间】:2017-06-23 21:47:43
【问题描述】:
我正在尝试将嵌入到 HTML 文件中的一些 JS 代码分开。我不拥有此代码,它用于远程支持登录页面,但我不确定如何将它们分开。
我尝试将 JS 代码复制到不同的 .js 文件中,然后将脚本标签添加到链接中,但没有成功。
<script type="text/javascript" src="https://www.islonline.net/webapi/api.js?
libs=join"></script>
<div class="isl-connect-form">
<form id="isl-connect-form" action="#" method="get" onsubmit="return
isl_connect();">
<fieldset>
<legend>Enter your session code and click Connect</legend>
<div>
<label for="isl-code-field">Session code</label>
<input type="text" name="code" id="isl-code-field" value="" />
</div>
<input type="submit" name="submit" value="Connect" />
</fieldset>
</form>
<div id="isl-feedback"></div>
</div>
<script type="text/javascript">
function isl_connect() {
var doc = document,
f = doc.getElementById('isl-connect-form'),
r = doc.getElementById('isl-feedback'),
is_msie = navigator.userAgent.indexOf('MSIE') >= 0,
b = null;
ISLOnline.Join.getSessionInfoByCode(
f.code.value,
function (info) {
r.className = 'isl-success';
r.innerHTML = 'Connecting to session ' +
info.getAttribute('sessionCode');
if (is_msie) {
r.innerHTML += ', please click the button below:<br />';
r.appendChild(doc.createElement('br'));
var b = doc.createElement('input');
b.type = 'button';
b.name = 'join';
b.value = 'Start';
b.onclick = function () {
info.join();
};
r.appendChild(b);
} else {
info.join();
}
},
function (error) {
r.className = 'isl-error';
r.innerHTML = 'Invalid session code!';
/* comment the line above and uncomment the line below if you
wish to
display the error that is sent by the server */
//r.innerHTML += error.getDescription();
}
);
return false;
}
【问题讨论】:
-
这不起作用?
-
现在你的问题是什么?
-
我试过 Kyle 但没有,当我点击提交按钮时,没有任何反应
-
@JHiggins,某些代码要求将其包含在页面上。我知道一些跟踪代码和类似的东西就是这样。尝试使用脚本标签,但将其移动到顶部,在已经存在的脚本标签下。
-
@Kyle1323 这是错误的。跟踪代码是不可移植的,这意味着它不能跨多个域应用,因为它是针对特定域进行硬编码的,但您仍然可以将其移动到单独的文件中并通过
src属性包含它,只要您遵循有关在 HTML 结构中放置<script>标记的建议(例如,在<body>的末尾或在<head>中等)
标签: javascript html