我试图获取位于第一个html页面上的底部粘贴的html代码的值。我有另一个html页面,应该用"onclick“按钮生成。更准确地说,代码应该在下一页中创建按钮。
Case1:收音机-选择-1被选中-它应该创建4个按钮。
Case2:收音机-选择-2被选中-它应该创建4或9个按钮。
Case3:收音机-选择-3被选中-它应该创建9或16个按钮。
Case4:收音机-选择-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>发布于 2014-09-02 20:11:34
我不知道你在找什么样的解决方案。但是,如果您不想使用根更深的东西,比如php中的$_SESSION变量,那么您可能在寻找类似cookies的东西。这里是一个伟大的曲奇一页。
还可以查看这教程中的htmlgoodies.com关于使用javascript传递变量的其他一些想法。
如果您对cookie没有意见,那么您可以使用已经拥有的内容,只需稍微清理一下jquery即可。
$(document).ready(function(){
$('#radio-button-value').click(function(){
var difficulty = $("input[name='radio-choice']:checked").val();
document.cookie = "gameDifficulty=" + difficulty + ";path=/";
});
});请参阅小提琴
https://stackoverflow.com/questions/25630468
复制相似问题