Javascript 新页面的单选按钮

Javascript 新页面的单选按钮,javascript,php,html,Javascript,Php,Html,嘿,伙计们,很抱歉问这个问题,但是我被难住了,我希望当单选按钮被点击时,代码能够转到带有动作的页面,就像愚蠢的单选按钮到dumby.php <form name = "quoted" method="get"> <input id = "poster" type="text" name="poster" required="required" placeholder = "Credited Individual."> <br>

嘿,伙计们,很抱歉问这个问题,但是我被难住了,我希望当单选按钮被点击时,代码能够转到带有动作的页面,就像愚蠢的单选按钮到dumby.php

<form name = "quoted" method="get">
    <input id = "poster" type="text" name="poster" required="required" placeholder = "Credited Individual.">     
    <br>
    <textarea class = "actual_quote" name = "actual_quote" required="required" placeholder = "Write the question here!"></textarea>
    <br><br><br>

    <div class = "checkboxes" required="required">
        <h3 style = "margin-top:-20px;">Please select one catagory that the quote falls into.</h3>
        <label for="x"><input type="radio" name="x" value="stupid" id = "x" checked="checked" action = "stupid.php" /><span>stupid</span></label>
        <br>
        <label for="x"><input type="radio" name="x" value="stupider" id = "x" action = "stupider.php" /><span>stupider</span></label>
        <br>
        <label for="x"><input type="radio" name="x" value="stupidest" id = "x" action = "stupidest.php" /><span>stupidest</span></label>
    </div>

    <input id = "submit1" type="submit"><br>
 </form>





请选择报价所属的一个类别。 愚蠢的
愚蠢的
愚蠢的
这是每个页面上的php,愚蠢的,愚蠢的,愚蠢的,愚蠢的,php错误是说实际的引用和海报没有被识别索引,帮助

    <div class="wrapper">
    <div class="submissions">
    <div class="logo-logo"><h2>Question.</h2>
    <div class="checkboxes"><?= !empty($_GET['x']) ? $_GET['x'] : '' ?>
    </div>

    </div>

 <div class="top-submit"><?php echo '&#8220;' . (!empty($_GET['actual_quote']) ?  $_GET['actual_quote'] : '') . '&#8221;'; $actual_quote = $_GET['actual_quote'];?>
 </div>
 <div class="poster"><?php echo "-" .  (!empty($_GET['poster']) ? $_GET['poster'] :''); $poster =  $_GET['poster'];?>
 <div class = "like">
 <a href = "javascript:countClicksLike();" class = "btn btn-large" style = "color:green;">Like</a>
 <p id = "like" style = "color:green;">0</p>
 </div>
 <div class = "dislike">
 <a href = "javascript:countClicks();" class = "btn btn-large" style = "float:right; color:red;">Dislike</a>
 <p id = "dis" style = "color:red;">0</p>
 </div>
  </div>
 <?php 
 "INSERT INTO submissions(top-submit, poster)
 VALUES ($actual_quote, $poster)";
?>
</div>
</div>

问题。

0

0

很抱歉问一下,我已经试了一个小时了,我的想法都没有了。欢迎提出任何建议

我只是想澄清一下,我希望每个单选按钮在被选中时,在单击“提交”按钮后,都会转到一个新页面,我希望让他们选中一个单选选项,然后单击“提交”并指向该页面。 v

 <label for="x"><input type="radio" name="x" value="stupid" id = "x" checked="checked" action = "stupid.php" />    <span>stupid</span></label><br>
因此,当用户单击任意一个单选按钮时,单击处理程序将带他进入
操作
属性中提到的相应页面


如果您只想在选中单选按钮时重定向,而不想在未选中单选按钮时重定向,请使用
if($(this).is(“:checked”)
检查条件

我不明白您为什么不使用
锚定
来重定向,而不是搞乱输入。如果使用锚定,则不需要对输入使用任何自定义的操作属性

此外,如果您有一个表单,那么为什么不简单地使用它的action属性呢。在后端,您可以轻松地处理重定向,而不是依赖javascript重定向

不过,如果您想使用输入进行导航和重定向,并且由于您没有提到任何关于jQuery的内容,我假设您需要纯Javascript解决方案。您可以在输入中使用内联javascript,如:

<label><input type="radio" action="http://www.google.com" onclick="window.location.href=this.action;"  />Google</label>
Google

如果您需要jQuery解决方案,请参考上面mohamedrias提供的解决方案。

您是否尝试根据单选按钮的选择将值发布到不同的php文件。如果是,我认为您可以使用jquery实现同样的功能

$("input[type='radio']").click(function(){
$("form").attr('action',$(this).attr('action'));
});

上面的代码将向所有单选按钮添加click事件处理程序。当用户单击单选按钮时,单选按钮中的action属性将设置为表单。提交表单时,它将调用当前所选单选按钮的action属性中的php文件集
$("input[type='radio']").click(function(){
$("form").attr('action',$(this).attr('action'));
});