我有一个完全正常工作的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';
}
}
}
答案 0 :(得分:1)
只需使用document.getElementById
form = document.getElementById('createquestion-form');