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.locationwindow.location.hrefなどのような多くの異なる小さなバリエーションを試しました。また、返品を台無しにして、私を狂わせてくれました。助けてくれてありがとう。皆さんは良い一日を過ごしています。

4

3 に答える 3

1

そもそもやってみようと思っています

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

しかし、私はさらに調査します。

私の考えは、次のことを試して、それが機能するかどうかを確認することです。

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

そうすれば、少なくとも、JavaScriptがブラウザなどで正しく機能しているかどうかがわかります。

joinはjavascript関数(配列で動作)であるため、joinから別の名前に名前を変更してみてください。競合している可能性がありますか?

于 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>

試すことができることの1つは、スクリプトを「ヘッド」セクションから本文に移動することです。

例えば:

<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コマンドの後)にスクリプトを配置してみることもできます。

また、それを2つのステートメントに分割してみることができます。おそらく、1行でそれを行うのは好きではありません。

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.hreftop.locationを試してください

以下はInternetExplorerで機能し、「ahref」の代わりにボタンがあります。

<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 に答える