Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
359 views
in Technique[技术] by (71.8m points)

javascript - 在选项中查找值并使用Javascript编辑CSS样式[重复](Finding values in options and editing css style using Javascript [duplicate])

My java script, which I got from a stack overflow question looks like this:(我从堆栈溢出问题中获得的Java脚本如下所示:)

<script type="text/javascript"> function search() { var a = document.getElementByClassName("s1"); var b = a.options[a.selectedIndex].value; if (b = 1) { document.getElementById("vmh").style.visibility = hidden } } </script> and there is a button that activates the function search, but the visibility is not changing(并且有一个按钮可以激活功能搜索,但是可见性没有改变)   ask by Alex translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Your if statement is not comparing values, but is instead assigning a value.(您的if语句不是比较值,而是分配一个值。)

b = 1 assigns 1 to the variable b .(b = 1受让人1到变量b 。) Instead, you'll want to use a comparison operator if (b == 1) .(相反, if (b == 1)需要使用比较运算符。) Secondly, the hidden should be wrapped in quotes.(其次, hidden应用引号引起来。) Currently you are assigning hidden to the visibility property, but hidden does not appear to be a variable.(当前,您正在将hidden分配给visibility属性,但是hidden似乎不是变量。) Instead, you'll do visibility = 'hidden' .(取而代之的是,您将可以看到visibility = 'hidden' 。)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...