我将xml文件中的数据显示为index.php,如下所示
function processXML($node){
foreach($node->children() as $agent => $data){
$agent= trim($agent);
if($agent=='image')
{
echo '<div><img src="'.$data.'" ></div>';
echo '<div>';
echo '</div>';
}
elseif($agent=='id')
{
echo '<div class = "Left">';
echo '<input type = "button" name="Agent" id = "'.$data.'" class = "subs-btn" value = "Select this Agent" OnClick = Selected(this.id);>';
$_SESSION['Selected'] = $data;
echo '</div>';
echo '<br/>';
echo '<br/>';
}
else
{
echo '<div class = "inline1">';
echo $data;
echo '</div>';
echo '<br/>';
}
processXML($data);
}
}
processXML($xml);
你们可以在这里看到我正在生成一个按钮并且onclick函数被调用 - Selected(this.id); 所以这是功能代码
function Selected(elem) {
var buttons = document.getElementsByClassName('subs-btn');
var length = buttons.length;
for (var i = 0; i < buttons.length; i++) {
buttons[i].style.backgroundImage="url('images/subs-btn.png')";
buttons[i].value="Select this Agent";
}
document.getElementById(elem).style.backgroundImage="url('images/subs-btn-act.png')";
document.getElementById(elem).value="Agent Selected";
}
因此选择了此代理。现在我在页面末尾有一个按钮
<input type = "submit" name="Continue" class = "btn btn-primary right" value = "Continue">
现在我想在另一个页面上显示与所选代理相关的数据。那么如何针对所选代理显示此数据? 请帮助。
答案 0 :(得分:1)
您需要遵循以下内容。这更像是伪造的代码,而不是实际的工作示例,因为我不知道你想要显示什么代理
注意:我假设您已包含jQuery。
<强> JS 强>
function Selected(elem) {
var buttons = document.getElementsByClassName('subs-btn');
var length = buttons.length;
for (var i = 0; i < buttons.length; i++) {
buttons[i].style.backgroundImage="url('images/subs-btn.png')";
buttons[i].value="Select this Agent";
}
document.getElementById(elem).style.backgroundImage="url('images/subs-btn-act.png')";
document.getElementById(elem).value="Agent Selected";
//Start here
var AgentData = ""//something about the agent. their id or some other identifier
//here you would make an ajax call to a php script
$.ajax({
type:"POST",
data: AgentData,
url: "someurl"
});
}
<强> PHP 强>
$_SESSION["AgentData"] = $_POST["AgentData"];
现在,只要有有效的会话,您就可以在任何地方访问有关所选代理的数据。