2014-09-02 185 views
0

我尝试获取位于第一个html页面上的底部粘贴html代码的值。我有另一个html页面,应该用“onclick”按钮生成。更准确地说,代码应该在下一页中创建按钮。如何从一个html页面获取单选按钮的值到另一个?

案例1:无线电选择-1被选中 - 它应该创建4个按钮。

情况2:选择无线电选择-2 - 它应该创建4或9个按钮。

案例3:选择radio-choice-3 - 它应该创建9或16个按钮。

案例4:无线电选择-4被选中 - 它应该创建16个按钮。

我不知道如何获得所选单选按钮的值,然后在另一页上生成按钮。

我其实有一点脚本(game.js):

$(document).ready(function(){ 
    $('#radio-button-value').click(function(){ 
     $("input[name='radio-button-gruppe']:checked".val()); 
    }); 
}); 

第一个HTML页面

 <html> 
    <head> 
     <meta charset="utf-8" /> 
     <title>newgame</title> 

     <link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.css" /> 
    <script src="http://code.jquery.com/jquery-1.8.2.min.js"></script> 
    <script src="http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.js"></script> 

    <!-- Einstellungen zur Defintion als WebApp --> 
    <meta name="apple-mobile-web-app-capable" content="yes" /> 
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"> 

    <script src="game.js"></script> 
    </head> 
    <body> 


    <div data-role="main" class="ui-content"> 
    <form> 
    <fieldset data-role="controlgroup"> 
    <legend>Choose a mode:</legend> 
    <input type="radio" name="radio-choice" id="radio-choice-1" value="choice-1" checked="checked"> 
    <label for="radio-choice-1">easy</label> 

    <input type="radio" name="radio-choice" id="radio-choice-2" value="choice-2"> 
    <label for="radio-choice-2">medium</label> 

    <input type="radio" name="radio-choice" id="radio-choice-3" value="choice-3"> 
    <label for="radio-choice-3">difficult</label> 

    <input type="radio" name="radio-choice" id="radio-choice-4" value="choice-4"> 
    <label for="radio-choice-4">hard</label> 
</fieldset> 
<input type="button" id="radio-button-value" name="game" value="create game" class="button" data-theme="b"/> 
</form> 





    </div> 

    <div data-role="footer"> 

    </div> 
</div> 
    </body> 
</html> 
+0

使用cookies为以下问题建议。这就是饼干的用途。存储一些数据。 – Tasos 2014-09-03 05:20:41

回答

0

我不知道你要找什么样的解决方案。但是如果你不想使用更深层次的东西,比如php中的$ _SESSION变量,那么你可能在寻找类似于cookies的东西。 Here是一个很棒的饼干网页。

还可以从htmlgoodies.com上查看this关于变量传递javascript的一些其他想法的教程。

如果你还没有使用cookies,你可以使用你已有的东西,只需要清理一下jquery。

$(document).ready(function(){ 
    $('#radio-button-value').click(function(){ 
     var difficulty = $("input[name='radio-choice']:checked").val(); 
     document.cookie = "gameDifficulty=" + difficulty + ";path=/"; 
    }); 
}); 

fiddle

+0

感谢哥们,多数民众赞成什么林搜索:) – dargudaka 2014-09-03 14:43:30

+0

当我在一个会话在PHP中,我怎么能设置的价值,以后得到的价值? – dargudaka 2014-09-03 15:22:11

相关问题