0

有一个烦人的小问题。找不到有效的解决方案,我尝试了从这里和谷歌搜索中找到的所有东西。

这样做的目的是将它们传递到先前创建的“房间”中。

似乎我尝试什么都没关系,我无法使用带有href的onclick将它加载到另一个页面中。而且我知道它很容易解决它只是我想不到的愚蠢。

抱歉,如果我没有正确地发布我的代码,这是我第一次问一个问题,我通常只是潜伏在周围寻找答案。

//..Left out <?php and my connect info but it is in my script
//--CLEANUP MY MESS
$sql = "SHOW TABLES";
$result = mysql_query($sql) or die('err11');
while ($row = mysql_fetch_row($result)) $testing[$row[0]] = true;// Gets a list of tables in the database and turns them into a handy format
if ($testing['prim']){// Checks to see if table prim exists
    $sql = "SELECT * FROM prim"; // Pulling all info again after cleaning
    $result = mysql_query($sql) or die('err11');
    $_e = '';
    while ($row = mysql_fetch_assoc($result)){// Cycle through enteries to see what rooms are up
        $_e = $_e . "<a href='' onclick='join(" . $row['room'] . ");'>" . $row['teach'] ."</a><br>";
    }
}else $_e = "Sorry no rooms are open";
mysql_close($con);
?>
<!DOCTYPE html>
<html>
<head>
<script>
function join(er) {
    alert('ffs is this even firing');//this is a debug statement i was using... it was firing
    //THE LINE BELOW DOES NOT SEEM TO WORK
    document.location = "http://***late edit to get rid of the web address lol sorry***start.php?name=" + document.getElementById("name").value + "&room=" + er;
    //THE LINE ABOVE DOES NOT WORK
}
</script>
<title>Portal</title>
</head>
<body>
Name:<input type="text" id='name' name="name"><br><?php echo $_e ?>
</body>
</html>

我尝试了许多不同的小变化,比如 window.location window.location.href 等等等等。也弄乱了退货,只是让我发疯 感谢任何帮助,你们度过了愉快的一天

4

3 回答 3

1

第一手我想试试

<a href='#' onclick=...

但我会进一步调查。

我的想法是尝试以下方法,看看它是否有效。

<a href="#" onclick="alert('hi');">hello</a>

那么至少这会告诉你javascript是否在你的浏览器等上正常工作。

您可以尝试将其从 join 重命名为另一个名称,因为 join 是一个 javascript 函数(在数组上操作),也许它有冲突?

于 2012-12-09T02:42:02.440 回答
1

window.open将为您打开一个新窗口。(见http://www.javascript-coder.com/window-popup/javascript-window-open.phtml

或者,您可以设置 href 并使用target="_blank". 这样您就不必使用 javascript,因此更易于访问。

于 2012-12-09T02:43:46.777 回答
1

尝试以下方法并告诉我它是否有效。然后尝试在顶部添加一些 PHP 代码,看看它是否仍然有效。

<script>
function test()
{
alert("testing");
document.location = "http://location_edited_out/provingground/start.php?name=abcd&room=1";
}
</script>
<a href="#" onclick="test()">hi</a>

您可以尝试的一件事是将脚本移出“头部”部分并进入正文。

例如:

<html>
<head><title>Portal</title>
</head><body>
<script>
function join(er) {
alert('ffs is this even firing');//this is a debug statement i was using... it was firing
//THE LINE BELOW DOES NOT SEEM TO WORK
document.location = "http://***late edit to get rid of the web address lol sorry***start.php?name=" + document.getElementById("name").value + "&room=" + er;
//THE LINE ABOVE DOES NOT WORK
}
</script>
Name:<input type="text" id='name' name="name"><br><?php echo $_e ?>
</body>
</html>

您也可以尝试将脚本放在正文的末尾(在 php echo 命令之后)。

您也可以尝试将它分成两个语句,也许它不喜欢在一行中这样做:

var url = "http://webaddr.com/start.php?name=" + document.getElementById("name").value + "&room=" + er;
document.location = url;

http://www.webmasterworld.com/javascript/3285118.htm

尝试 window.location.href 或简单地, location.href top.location

?

以下适用于 Internet Explorer,有一个按钮而不是“a href”。

<html>
<body>
<script>
function test()
{
alert("testing");
window.location.assign("http://location_edited_out/provingground/start.php?name=abcd&room=1")
}
</script>

<input type='button' value='Load new document' onclick='test()'>
</body></html>

不确定这是否是一个选项?

所以代码是:

while ($row = mysql_fetch_assoc($result)){// Cycle through enteries to see what rooms are up
    $_e = $_e . "<input type='button' onclick='join(" . $row['room'] . ");' value='" . $row['teach'] ."'><br>";
}
...
function join(er) {
    alert('ffs is this even firing');//this is a debug statement i was using... it was firing
    window.location.assign( "http://***late edit to get rid of the web address lol sorry***start.php?name=" + document.getElementById("name").value + "&room=" + er);
}

让我知道它是否有效。

于 2012-12-09T03:12:42.583 回答