Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/454.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何更改接收id以外的背景图像_Javascript_Php_Xml - Fatal编程技术网

Javascript 如何更改接收id以外的背景图像

Javascript 如何更改接收id以外的背景图像,javascript,php,xml,Javascript,Php,Xml,我有两个文件 php和agent.xml agent.xml中的数据 <?xml version="1.0" encoding="ISO-8859-1"?> <agents> <agent> <image> img/sara.jpg</image> <id>1</id> <name>Tommy Jenkin</name> <company>

我有两个文件 php和agent.xml agent.xml中的数据

<?xml version="1.0" encoding="ISO-8859-1"?>
<agents>
    <agent>
    <image> img/sara.jpg</image>
    <id>1</id>
    <name>Tommy Jenkin</name>
    <company>CJenkins Insurance</company>
    <street>Insurance150 S State Stree</street>
    <city>Linkend</city>
    <phone>(773) 561-4331</phone>
    </agent>
    <agent>
    <image> img/primary-nav-logo.png</image>
    <id>2</id>
    <name>saka</name>
    <company>LIC Insurance</company>
    <street>Insurance150 S State Stree</street>
    <city>Linkend</city>
    <phone>(773) 561-4331</phone>
    </agent>
</agents>
现在我不知道如何将所有其他按钮的图像更改为默认图像。我的意思是,若我点击一个按钮,那个么那个特定按钮的背景图像应该改变。然后,如果我点击了另一个按钮,第一个点击的按钮会将背景图像更改为默认值


请建议我如何操作。

记住以前选择的按钮,并在选择新按钮时将其bg图像更改回默认值。 通过清除指定的bg映像,将其更改回默认值:

function Selected(elem) 
{
 if(previous) { document.getElementById(previous).style.backgroundImage=""; }
 document.getElementById(elem).style.backgroundImage="url('images/subs-btn-act.png')";
 previous = elem; // remember current selection
 unselected();
}
echo '<input type = "button" name="Agent" id = "'.$data.'" class = "subs-btn" value = "Select this Agent" OnClick = Selected(this.id);>';
function Selected(elem) 
                {
                    alert(elem);
                    document.getElementById(elem).style.backgroundImage="url('images/subs-btn-act.png')";
                    unselected();
                }
function Selected(elem) 
{
 if(previous) { document.getElementById(previous).style.backgroundImage=""; }
 document.getElementById(elem).style.backgroundImage="url('images/subs-btn-act.png')";
 previous = elem; // remember current selection
 unselected();
}