Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/273.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 自动显示列表的Jquery函数_Javascript_Jquery - Fatal编程技术网

Javascript 自动显示列表的Jquery函数

Javascript 自动显示列表的Jquery函数,javascript,jquery,Javascript,Jquery,我希望用户从国家/地区列表中选择国家/地区。当一个国家被选中时,它将从列表1中消失并转到列表2。以下是我的代码: Select countries:<br> <div name="a1" id="a1"><a style="cursor:pointer" onClick="document.getElementById('f1').style.display='block';addcnt('Bulgaria');">Bulgaria</a><

我希望用户从国家/地区列表中选择国家/地区。当一个国家被选中时,它将从列表1中消失并转到列表2。以下是我的代码:

Select countries:<br>
<div name="a1" id="a1"><a style="cursor:pointer" onClick="document.getElementById('f1').style.display='block';addcnt('Bulgaria');">Bulgaria</a><br></div>
<div name="a2" id="a2"><a style="cursor:pointer" onClick="document.getElementById('f2').style.display='block';addcnt('Russia');">Russia</a><br></div>

Selected countries:<br>
<div name="f1" id="f1" style="display: none;"><img  style="cursor:pointer" onClick="document.getElementById('f1').style.display='none';document.getElementById('a1').style.display='block';" src='images/delete.png' /><img src='images/flags/bg.jpg' />Bulgaria</div>
<div name="f2" id="f2" style="display: none;"><img  style="cursor:pointer" onClick="document.getElementById('f2').style.display='none';document.getElementById('a2').style.display='block';" src='images/delete.png' /><img src='images/flags/ru.jpg' />Russia</div>
还有javascript:

<script>
$("#a1").click(function ( event ) {
event.preventDefault();
$(this).hide();
});
$("#a2").click(function ( event ) {
event.preventDefault();
$(this).hide();
});
</script>
这是工作部分。因此,我希望这些国家在一个列表中,以隐藏的方式动态显示,列表由comas分隔。以下是:

<div id='countriesvb' style='display:none;'>
<p><b>Countries you've selected</b></p>
</div>
<br /><br />
<form method='post' name='frm'>
<input type='hidden' name='countries' id='countries' value=''>
</form>
我试图在名为addcnt的javascript函数中创建列表,但有些东西不起作用。这就是函数

function addcnt(ps)
{
var cylist = document.frm.countries.value;
document.frm.countries.value = cylist + ',' + ps;
var khs = document.getElementById('countriesvb').innerHTML;
document.getElementById('countriesvb').style.display = 'block';
document.getElementById('countriesvb').innerHTML = khs + ps + \"<br />\";
}

你能帮我找到问题吗?

它不起作用,因为你的上一个陈述:

document.getElementById('countriesvb').innerHTML = khs + ps + \"<br />\";
下面是一个工作示例:

<div id='countriesvb' style='display:none;'>
    <p>
        <b>Countries you've selected</b>
    </p>
    <span id="selected-countries"></span> *** you should to add this span.
</div>
function addcnt(ps)
{
    document.frm.countries.value = !document.frm.countries.value ? ps : document.frm.countries.value + "," + ps;
    var khs = document.frm.countries.value;
    document.getElementById('countriesvb').style.display = 'block';
    document.getElementById('selected-countries').innerHTML = khs;
}