0

我有一个完全工作的js,但我的问题是。我确实将它包含在另一个程序员生成的 php 文件中。该文件非常大,我无法重写所有内容。

在我的 js 中,我使用这个:document.myform1.cid.options[i].selected = true;

但我的问题是表单的 id 是createquestion-form. 它没有名字。

我怎么replace myform1可能createquestion-form

这是我的完整脚本:

function Search()
            {
                var SearchKeyWord=document.getElementById("SearchText").value;
                var SelLength=document.myform1.cid.length;
                for(var i=0; i<SelLength;i++)
                {
                    var searched_text = document.myform1.cid.options[i].text;
                    var IsMatch = searched_text.search(SearchKeyWord);
                    if(IsMatch != -1)
                    {
                        document.myform1.cid.options[i].selected = true;
                        document.myform1.cid.options[i].style.color = 'red';
                    }
                    else
                    {
                        document.myform1.cid.options[i].style.color = 'black';
                    }
                }
            }
4

1 回答 1

1

只需使用document.getElementById

form = document.getElementById('createquestion-form');
于 2013-05-19T11:56:43.797 回答