您好我正在尝试将我的HTML / PHP / JS / XML页面迁移到一个php文件中。我能够成功地使用4个文件成功地使我的应用程序,但当我把它们放入一个似乎我的js和php是冲突的,如果有一种方法我可以使单选按钮设置为默认没有选项,因为我我猜这就是问题所在。
嗯我已经解决了关于单选按钮的问题,无论如何我试图将它们全部放在一个页面上,因为我试图模仿本地程序的输出,当我看到输出时我意识到这一点我的第一次尝试。所以我现在正在尝试做的是在运行php代码之后我想将它们放在div中,这样它们就不会飞到各处。我已经解决了这个问题,但我现在的问题是当我在我的选项中选择下一个单选按钮时,除非我点击我的提交按钮,否则之前请求的结果仍然存在。我猜它与我传递给我的html主体的js有关。尝试修复js中的div问题但是它只是显示了div一瞬间。
这是我的代码:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Globe2Smac</title>
<link rel="stylesheet" href="css/mycss.css" type="text/css">
<script src="js/hide.js" type="text/javascript"></script>
</head>
<body onLoad="">
<h2>Globe to SMAC Function</h2>
<form method="post" action="">
<div>
<ul style="list-style:none">
<li><input id="smember" type ="radio" name ="option" value = "SmacMembers" onChange="SMmember()" checked/>SMAC MEMBERS</li>
<li><input id="sbalance"type ="radio" name ="option" value = "SmacBalance" onChange="SMbalance()" checked/>SMAC BALANCE QUERY</li>
<li><input id="saward" type ="radio" name ="option" value = "SmacAward" onChange="SMaward()" checked/>SMAC AWARD</li>
<li><input id="sredemption" type ="radio" name ="option" value = "SmacRedeem" onChange="SMredeem()" checked/>SMAC REDEMPTION</li>
</ul>
<div>Globe XML RPC Request:</div>
<div id="smmember" class="div-border" style="display:none"><textarea id="areamember" name="gmember" value="Member" spellcheck="false">
<?xml version="1.0" encoding="UTF-8"?>
<methodCall>
<methodName>smac.members</methodName>
<params>
<param>
<value>
<string>
&lt;?xml version="1.0"?&gt;
&lt;globetosmac&gt;
&lt;functioncode&gt;smac_members&lt;/functioncode&gt;
&lt;cardnumber&gt;8880999521960565&lt;/cardnumber&gt;
&lt;transaction_id&gt;12345678&lt;/transaction_id&gt;
&lt;/globetosmac&gt;
</string>
</value>
</param>
</params>
</methodCall></textarea></div>
<div id="smbalancequery"class="div-border" style="display:none"><textarea id="areabalance" name="gbalance" value="Balance" spellcheck="false">
<?xml version="1.0" encoding="UTF-8"?>
<methodCall>
<methodName>smac.balance_query</methodName>
<params>
<param><value><string>
&lt;?xml version="1.0"?&gt;
&lt;globetosmac&gt;
&lt;functioncode&gt;smac_balance_query&lt;/functioncode&gt;
&lt;cardnumber&gt;8880999521960565&lt;/cardnumber&gt;
&lt;transaction_id&gt;1441795&lt;/transaction_id&gt;
&lt;birthday&gt;01011900&lt;/birthday&gt;
&lt;transactiondatetime&gt;2011-09-16 13:43:58&lt;/transactiondatetime&gt;
&lt;/globetosmac&gt;
</string></value></param>
</params>
</methodCall>
</textarea></div>
<div id="smaward" class="div-border"style="display:none"><textarea id="areaward" name="gaward" value="Award" spellcheck="false">
<?xml version="1.0" encoding="UTF-8"?>
<methodCall>
<methodName>smac.award_points</methodName>
<params>
<param>
<value>
<string>
&lt;?xml version="1.0"?&gt;
&lt;globetosmac&gt;
&lt;functioncode&gt;smac_award_points&lt;/functioncode&gt;
&lt;cardnumber&gt;8880999521060440&lt;/cardnumber&gt;
&lt;transaction_id&gt;1441795&lt;/transaction_id&gt;
&lt;transaction_amount&gt;100&lt;/transaction_amount&gt;
&lt;transaction_code&gt;OFLN-GLOBE&lt;/transaction_code&gt;
&lt;transactiondatetime&gt;2011-09-22 16:20:58&lt;/transactiondatetime&gt;
&lt;/globetosmac&gt;
</string>
</value>
</param>
</params>
</methodCall></textarea></div>
<div id="smredemption" class="div-border"style="display:none"><textarea id="arearedeem" name="gredeem" value="Redeem" spellcheck="false">
<?xml version="1.0" encoding="UTF-8"?>
<methodCall>
<methodName>smac.redemption_points</methodName>
<params>
<param>
<value>
<string>
&lt;?xml version="1.0"?&gt;
&lt;globetosmac&gt;
&lt;functioncode&gt;smac_redemption_points&lt;/functioncode&gt;
&lt;cardnumber&gt;8880999521060440&lt;/cardnumber&gt;
&lt;transaction_id&gt;1441795&lt;/transaction_id&gt;
&lt;transaction_amount&gt;10&lt;/transaction_amount&gt;
&lt;transaction_code&gt;OFLN-GLOBE&lt;/transaction_code&gt;
&lt;transactiondatetime&gt;20110921 16:20:58&lt;/transactiondatetime&gt;
&lt;/globetosmac&gt;
</string>
</value>
</param>
</params>
</methodCall></textarea></div>
<div id="submit"><input type="submit" name="Submit" value="Submit Query"></div>
<div>Globe XML Response:</div>
<div class="div-border"><?php
if($_POST['option'] == "SmacMembers"){
$member = $_POST['gmember'];
$URL = 'https://localhost/globe2smac-fh3/api/';
$ch = curl_init($URL);
//curl_setopt($ch, CURLOPT_URL, "https://localhost/globe2smac-fh3/api");
curl_setopt($ch, CURLOPT_MUTE, 1);
curl_setopt($ch, CURLOPT_USERPWD, "michael:kel");
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/html'));
curl_setopt($ch, CURLOPT_POSTFIELDS, $member);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 2);
$MemResult = curl_exec($ch);
curl_close($ch);
}
else if($_POST['option'] == "SmacBalance"){
$balance= $_POST['gbalance'];
echo $balance;
$URL = "https://localhost/globe2smac-fh3/api/";
$ch = curl_init($URL);
curl_setopt($ch, CURLOPT_MUTE, 1);
curl_setopt($ch, CURLOPT_USERPWD, "michael:kel");
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
curl_setopt($ch, CURLOPT_POSTFIELDS, "$balance");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$BalResult= curl_exec($ch);
curl_close($ch);
echo $output;
}
else if($_POST['option'] == "SmacAward"){
$award=$_POST['gaward'];
echo $award;
$URL = "https://localhost/globe2smac-fh3/api/";
$ch = curl_init($URL);
curl_setopt($ch, CURLOPT_MUTE, 1);
curl_setopt($ch, CURLOPT_USERPWD, "michael:kel");
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
curl_setopt($ch, CURLOPT_POSTFIELDS, "$award");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
echo $output;
}
else if($_POST['option'] == "SmacRedeem"){
$redeem=$_POST['gredeem'];
echo $redeem;
$URL = "https://localhost/globe2smac-fh3/api/";
$ch = curl_init($URL);
curl_setopt($ch, CURLOPT_MUTE, 1);
curl_setopt($ch, CURLOPT_USERPWD, "michael:kel");
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
curl_setopt($ch, CURLOPT_POSTFIELDS, "$redeem");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$RedResult = curl_exec($ch);
curl_close($ch);
echo $output;
}
else{
echo('Option not Found');
}
?></div>
</div>
</form>
</body>
</html>
将我的代码重新更新为:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Globe2Smac</title>
<link rel="stylesheet" href="css/mycss.css" type="text/css">
<script src="js/hide.js" type="text/javascript"></script>
</head>
<body onLoad="siteLoad();">
<h2>Globe to SMAC Function</h2>
<form method="post" action="">
<div>
<ul style="list-style:none">
<li><input id="smember" type ="radio" name ="option" value = "SmacMembers" onChange="SMmember()" />SMAC MEMBERS</li>
<li><input id="sbalance"type ="radio" name ="option" value = "SmacBalance" onChange="SMbalance()"/>SMAC BALANCE QUERY</li>
<li><input id="saward" type ="radio" name ="option" value = "SmacAward" onChange="SMaward()"/>SMAC AWARD</li>
<li><input id="sredemption" type ="radio" name ="option" value = "SmacRedeem" onChange="SMredeem()"/>SMAC REDEMPTION</li>
</ul>
<div>Globe XML RPC Request:</div>
<div id="smmember" class="div-border" style="display:none"><textarea id="areamember" name="gmember" value="Member" spellcheck="false">
<?xml version="1.0" encoding="UTF-8"?>
<methodCall>
<methodName>smac.members</methodName>
<params>
<param>
<value>
<string>
&lt;?xml version="1.0"?&gt;
&lt;globetosmac&gt;
&lt;functioncode&gt;smac_members&lt;/functioncode&gt;
&lt;cardnumber&gt;8880999521960565&lt;/cardnumber&gt;
&lt;transaction_id&gt;12345678&lt;/transaction_id&gt;
&lt;/globetosmac&gt;
</string>
</value>
</param>
</params>
</methodCall></textarea></div>
<div id="smbalancequery"class="div-border" style="display:none"><textarea id="areabalance" name="gbalance" value="Balance" spellcheck="false">
<?xml version="1.0" encoding="UTF-8"?>
<methodCall>
<methodName>smac.balance_query</methodName>
<params>
<param><value><string>
&lt;?xml version="1.0"?&gt;
&lt;globetosmac&gt;
&lt;functioncode&gt;smac_balance_query&lt;/functioncode&gt;
&lt;cardnumber&gt;8880999521960565&lt;/cardnumber&gt;
&lt;transaction_id&gt;1441795&lt;/transaction_id&gt;
&lt;birthday&gt;01011900&lt;/birthday&gt;
&lt;transactiondatetime&gt;2011-09-16 13:43:58&lt;/transactiondatetime&gt;
&lt;/globetosmac&gt;
</string></value></param>
</params>
</methodCall>
</textarea></div>
<div id="smaward" class="div-border"style="display:none"><textarea id="areaward" name="gaward" value="Award" spellcheck="false">
<?xml version="1.0" encoding="UTF-8"?>
<methodCall>
<methodName>smac.award_points</methodName>
<params>
<param>
<value>
<string>
&lt;?xml version="1.0"?&gt;
&lt;globetosmac&gt;
&lt;functioncode&gt;smac_award_points&lt;/functioncode&gt;
&lt;cardnumber&gt;8880999521060440&lt;/cardnumber&gt;
&lt;transaction_id&gt;1441795&lt;/transaction_id&gt;
&lt;transaction_amount&gt;100&lt;/transaction_amount&gt;
&lt;transaction_code&gt;OFLN-GLOBE&lt;/transaction_code&gt;
&lt;transactiondatetime&gt;2011-09-22 16:20:58&lt;/transactiondatetime&gt;
&lt;/globetosmac&gt;
</string>
</value>
</param>
</params>
</methodCall></textarea></div>
<div id="smredemption" class="div-border"style="display:none"><textarea id="arearedeem" name="gredeem" value="Redeem" spellcheck="false">
<?xml version="1.0" encoding="UTF-8"?>
<methodCall>
<methodName>smac.redemption_points</methodName>
<params>
<param>
<value>
<string>
&lt;?xml version="1.0"?&gt;
&lt;globetosmac&gt;
&lt;functioncode&gt;smac_redemption_points&lt;/functioncode&gt;
&lt;cardnumber&gt;8880999521060440&lt;/cardnumber&gt;
&lt;transaction_id&gt;1441795&lt;/transaction_id&gt;
&lt;transaction_amount&gt;10&lt;/transaction_amount&gt;
&lt;transaction_code&gt;OFLN-GLOBE&lt;/transaction_code&gt;
&lt;transactiondatetime&gt;20110921 16:20:58&lt;/transactiondatetime&gt;
&lt;/globetosmac&gt;
</string>
</value>
</param>
</params>
</methodCall></textarea></div>
<div id="submit"><input type="submit" name="Submit" value="Submit XML Request"></div>
<div>Globe XML Response:</div>
<div class="div-border"><?php
if($_POST['option'] == "SmacMembers"){
$member = $_POST['gmember'];
$URL = 'https://localhost/globe2smac-fh3/api/';
$ch = curl_init($URL);
//curl_setopt($ch, CURLOPT_URL, "https://localhost/globe2smac-fh3/api");
curl_setopt($ch, CURLOPT_MUTE, 1);
curl_setopt($ch, CURLOPT_USERPWD, "michael:kel");
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/html'));
curl_setopt($ch, CURLOPT_POSTFIELDS, $member);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 2);
$MemResult = curl_exec($ch);
curl_close($ch);
echo $MemResult;
}
else if($_POST['option'] == "SmacBalance"){
$balance= $_POST['gbalance'];
$URL = "https://localhost/globe2smac-fh3/api/";
$ch = curl_init($URL);
curl_setopt($ch, CURLOPT_MUTE, 1);
curl_setopt($ch, CURLOPT_USERPWD, "michael:kel");
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
curl_setopt($ch, CURLOPT_POSTFIELDS, "$balance");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$BalResult= curl_exec($ch);
curl_close($ch);
echo $BalResult;
}
else if($_POST['option'] == "SmacAward"){
$award=$_POST['gaward'];
echo $award;
$URL = "https://localhost/globe2smac-fh3/api/";
$ch = curl_init($URL);
curl_setopt($ch, CURLOPT_MUTE, 1);
curl_setopt($ch, CURLOPT_USERPWD, "michael:kel");
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
curl_setopt($ch, CURLOPT_POSTFIELDS, "$award");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$Awresult= curl_exec($ch);
curl_close($ch);
echo $Awresult;
}
else if($_POST['option'] == "SmacRedeem"){
$redeem=$_POST['gredeem'];
echo $redeem;
$URL = "https://localhost/globe2smac-fh3/api/";
$ch = curl_init($URL);
curl_setopt($ch, CURLOPT_MUTE, 1);
curl_setopt($ch, CURLOPT_USERPWD, "michael:kel");
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
curl_setopt($ch, CURLOPT_POSTFIELDS, "$redeem");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$RedResult = curl_exec($ch);
curl_close($ch);
echo $RedResult;
}
else{
echo('Processing Requests...');
}
?></div>
</div>
</form>
</body>
</html>
答案 0 :(得分:0)
现在您已将所有单选按钮设置为已选中;
<input type="radio" ... checked />
首先,正确的语法是:
<input type="radio" ... checked="checked" />
此外,请确保只选中一个单选按钮(这是单选按钮的性质:))或使用复选框
只是一个问题;为什么要将所有内容合并到一个文件中?为了可维护性,大多数时候将代码分开是个不错的主意!