【问题标题】:How to add a $variable to a onclick="location.href='如何将 $ 变量添加到 onclick="location.href='
【发布时间】:2014-05-19 13:39:23
【问题描述】:

您好,我需要帮助,因为这不起作用: 我只是想打开带有按钮但在搜索框中的网站.....

<html>
<body>
    <form>
        <input type=button onClick=window.open("action.php","demo","width=550,height=300,left=150,top=200,toolbar=0,status=0,"); value="Öffne">
    </form>
    <form method="post" action="action.php">Suche: <input name="suche" type="text"><br>
        <input type="submit" value="OK">
    </form>
</body>
</html>


<php
$user = $_POST['suche'];
$seite = 'www.google.de/#q=';
$ziel=$seite.$user;



<form>
      <input type=button onclick="location.href='https://www.google.de/#q=<?php echo $seite; ?>'" value='Website'>
      <input type=button onClick="self.close();" value="Close this window">
</form>

【问题讨论】:

  • 我没有得到这个问题。您能否更详细地解释一下您想要实现的目标以及到目前为止所做的工作?
  • 对不起我的错误解释......我写下了我最近的问题以及到目前为止我所做的事情作为这个主题底部的答案,在此先感谢。 :)

标签: php html button


【解决方案1】:

html 标签 attr 和 php 结束标签 try 上缺少更多引号

<html>
<body>
<form>
<input type="button" onClick='window.open("action.php","demo","width=550,height=300,left=150,top=200,toolbar=0,status=0,");' value="Öffne">
</form>
<form method="post" action="action.php">Suche: <input name="suche" type="text"><br>
     <input type="submit" value="OK">
</form>
</body>
</html>
<?php
$user = $_POST['suche'];
$seite = 'www.google.de/#q=';
$ziel=$seite.$user;
?>
<form>
<input type="button" onclick="location.href='https://www.google.de/#q=<?php echo $seite; ?>'" value='Website'>
<input type="button" onClick="self.close();" value="Close this window">
</form>

【讨论】:

  • 请点赞或接受您认为有帮助的答案
  • 好的,我接受了答案,感谢您的帮助,但我还有一个问题,如果您能帮助我,我将非常感谢...
  • 我在本主题的底部写下了我的问题作为答案,如果你能看一下... :)
【解决方案2】:

现在我有最后一个问题,我想将两个文件 index.html 和 action.php 放在一个文件中。因此,如果我继续使用 Index.html,我只需输入“suche”的值并单击提交按钮(“ok”)以将“name”的值保存到“$input”中,然后单击其中一个按钮google,proxer,.... 在该网站上进行搜索。 (如果可能的话,我可以合并提交按钮('OK')和按钮(google,proxer,...)以使其更清洁)

例如,google + $input 的链接是:$seite_google.$input;

我的代码现在看起来像:

对于 index.php:

 <?php
   $input = $_POST['suche'];
    $seite_google = 'https://www.google.de/#q=';
    $seite_myanimelist = 'http://myanimelist.net/anime.php?q=';
    $seite_anisearch = 'http://de.anisearch.com/anime/index/?char=all&text=';
    $seite_proxer = 'http://proxer.me/search?name=';
    ?>
    <form>
    <input type="button" onclick="location.href='<?php echo $seite_google.$input; ?>'" value='Google Suche'>
    <input type="button" onclick="location.href='<?php echo $seite_myanimelist.$input; ?>'" value='MyAnimeList'>
    <input type="button" onclick="location.href='<?php echo $seite_anisearch.$input; ?>&q=true'" value='AniSearch'>
    <input type="button" onclick="location.href='<?php echo $seite_proxer.$input; ?>&sprache=alle&typ=all&genre=&nogenre=&sort=name&length=&length-limit=down#search'" value='Proxer'>
    </form>

    <html>
    <body>
    <form method="post" action="">Suche: <input name="suche" type="text"><br>
         <input type="submit" value="OK" name="submit">
    </form>
    </body>
    </html>

【讨论】:

  • 那么你有什么问题
  • 代码运行没有问题。现在我想将 index.html 和 action.php 合并到一个文件(html 或 php)中,这样 index.html 就不必打开 action.php。
  • 伙计,它正在工作,但是否可以在一个页面上显示两种表单,而不是一个提交按钮,只需在 textlabel ('suche') 中输入文本并单击一个开始搜索的 4 个按钮中的哪一个(例如在 google 上)?
  • 嗯,它不起作用,我删除了 if 行和 else 行,但它只显示了第一个带有一个按钮的表单(不是带有 4 个按钮的那个)?
  • :D its workinggggggg... 最后一个问题是我可以删除提交按钮('OK')并使用其他按钮将 name="suche" 的值放入 $input 吗?谢谢人:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-11-22
  • 2019-09-13
  • 1970-01-01
  • 2021-03-03
  • 2014-03-10
  • 2017-10-01
相关资源
最近更新 更多