【发布时间】:2010-03-15 00:50:05
【问题描述】:
我正在使用 kottke.org 的旧 JAH 示例将一些 html 返回到网页中的 div。如果我使用静态文本,代码可以正常工作。但是我需要获取一个字段的值以添加到作为参数传递给函数的字符串中。
var xmlhttp=false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
xmlhttp = false;
}
}
@end @*/
if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
xmlhttp = new XMLHttpRequest();
}
function getMyHTML(serverPage, objID) {
var obj = document.getElementById(objID);
xmlhttp.open("GET", serverPage);
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
obj.innerHTML = xmlhttp.responseText;
}
}
xmlhttp.send(null);
}
在页面上......
<a href="javascript://" onclick="getMyHTML('/WStepsDE?open&category="+document.getElementById('Employee').value;+"','goeshere')">Change it!</a></p>
<div id ="goeshere">Hey, this text will be replaced.</div>
我尝试获取 Employee 的值以包含在第一个参数中的 getMyHTML 调用失败(在 Firebug 的帮助下)。错误是“未终止的字符串文字”。提前感谢您的帮助。
【问题讨论】:
-
您应该将其中一个标记为正确答案,以便将来的人们知道它有效。
标签: javascript function concatenation