Javascript 用于下拉和删除内容的文本框

Javascript 用于下拉和删除内容的文本框,javascript,jquery,html,css,Javascript,Jquery,Html,Css,我有两个代码从文本框中获取内容,并将它们放在下拉框中,我有一个5页的表单,使用javascript和onclick function在页面之间切换,在第3步,我有9个文本框,在其中,一旦我单击next,就会输入名称,我有一个复制功能,它将复制9文本框中的名称,然后放入一个下拉框中,但是当我单击返回到第3步并单击下一步时,下拉框中的内容是重复的。我如何更正代码,以便在单击返回时,我有一个功能,删除下拉框上的旧内容代码如下;我还附上了一个屏幕截图,显示了当你点击后退时发生的事情 这是用于将文本框内容

我有两个代码从文本框中获取内容,并将它们放在下拉框中,我有一个5页的表单,使用javascript和onclick function在页面之间切换,在第3步,我有9个文本框,在其中,一旦我单击next,就会输入名称,我有一个复制功能,它将复制9文本框中的名称,然后放入一个下拉框中,但是当我单击返回到第3步并单击下一步时,下拉框中的内容是重复的。我如何更正代码,以便在单击返回时,我有一个功能,删除下拉框上的旧内容代码如下;我还附上了一个屏幕截图,显示了当你点击后退时发生的事情

这是用于将文本框内容复制到下拉框的函数

<script type="text/javascript">
function data_copy()
{
    if(document.forms[0].health1.value == ""){
        var select = document.getElementById("health1");
        var value = "";
        select.options[select.options.length] = new Option(value, value);
        var value = document.form1.passName1.value;
        select.options[select.options.length] = new Option(value, value);
        var value = document.form1.passName2.value;
        select.options[select.options.length] = new Option(value, value);
        var value = document.form1.passName3.value;
        select.options[select.options.length] = new Option(value, value);
        var value = document.form1.passName4.value;
        select.options[select.options.length] = new Option(value, value);
        var value = document.form1.passName5.value;
        select.options[select.options.length] = new Option(value, value);
        var value = document.form1.passName6.value;
        select.options[select.options.length] = new Option(value, value);
        var value = document.form1.passName7.value;
        select.options[select.options.length] = new Option(value, value);
        var value = document.form1.passName8.value;
        select.options[select.options.length] = new Option(value, value);
        var value = document.form1.passName9.value;
        select.options[select.options.length] = new Option(value, value);
    }else{
        document.form1.pass1Name.value="";
        document.form1.pass2Name.value="";
        document.form1.pass3Name.value="";
        document.form1.pass4Name.value="";
        document.form1.pass5Name.value="";
        document.form1.pass6Name.value="";
        document.form1.pass7Name.value="";
        document.form1.pass8Name.value="";
        document.form1.pass9Name.value="";
    }
}
</script>

函数数据_copy()
{
if(document.forms[0].health1.value==“”){
var select=document.getElementById(“health1”);
var值=”;
select.options[select.options.length]=新选项(值,值);
var值=document.form1.passName1.value;
select.options[select.options.length]=新选项(值,值);
var值=document.form1.passName2.value;
select.options[select.options.length]=新选项(值,值);
var值=document.form1.passName3.value;
select.options[select.options.length]=新选项(值,值);
var值=document.form1.passName4.value;
select.options[select.options.length]=新选项(值,值);
var值=document.form1.passName5.value;
select.options[select.options.length]=新选项(值,值);
var值=document.form1.passName6.value;
select.options[select.options.length]=新选项(值,值);
var值=document.form1.passName7.value;
select.options[select.options.length]=新选项(值,值);
var值=document.form1.passName8.value;
select.options[select.options.length]=新选项(值,值);
var值=document.form1.passName9.value;
select.options[select.options.length]=新选项(值,值);
}否则{
document.form1.pass1Name.value=“”;
document.form1.pass2Name.value=“”;
document.form1.pass3Name.value=“”;
document.form1.pass4Name.value=“”;
document.form1.pass5Name.value=“”;
document.form1.pass6Name.value=“”;
document.form1.pass7Name.value=“”;
document.form1.pass8Name.value=“”;
document.form1.pass9Name.value=“”;
}
}
调用操作代码以复制下拉框中的项目

<a href="#" onclick="data_copy(); "><img src="images/step4.jpg" border="0" width="30%" />

这是back函数,我需要删除下拉列表中的旧内容,因为它们正在复制

<script type="text/javascript">
function data_nocopy()
{
    if(document.forms[0].health1.value > 0){
        var select = document.getElementById("health1");
        var value = "";
        select.options[select.options.length] = new Option(value, value);
    }
}
</script>

函数数据_nocopy()
{
if(document.forms[0].health1.value>0){
var select=document.getElementById(“health1”);
var值=”;
select.options[select.options.length]=新选项(值,值);
}
}
调用函数以擦除但不工作

![<a href="#" onclick="data_nocopy(); "><img src="images/step4.jpg" border="0" width="30%" />][1]
![][1]

非常感谢希望您能帮助我,谢谢

据我所知,您想清除dropdownlist项目。下面给出了示例代码

在Jquery中

$('#health1')[0].options.length = 0;
document.getElementById("health1").options.length = 0;
Javascript中的

$('#health1')[0].options.length = 0;
document.getElementById("health1").options.length = 0;