JavaScript边框颜色/颜色样式

JavaScript边框颜色/颜色样式,javascript,colors,border-color,Javascript,Colors,Border Color,我想使用JS为表单(IE的悬停效果)的“input.submit”设置样式,并尝试了下面的方法,但不幸的是没有成功 <!--[if IE]> <script type="text/javascript"> // CHANGE SUBMIT STYLE var foo = document.getElementByClass('input.submit'); foo.onmouseover = this.style.border-color='#000000'; this

我想使用JS为表单(IE的悬停效果)的“input.submit”设置样式,并尝试了下面的方法,但不幸的是没有成功

<!--[if IE]>
<script type="text/javascript">

// CHANGE SUBMIT STYLE
var foo = document.getElementByClass('input.submit');
foo.onmouseover = this.style.border-color='#000000'; this.style.color='#000000';
foo.onmouseout = this.style.border-color='#888888'; this.style.color='#888888';
foo.onclick = this.style.border-color='#000000'; this.style.color='#000000';

</script>
<![endif]-->

你能帮我修一下吗?TIA、Dan应该是:

foo.onmouseover = function() {
    this.style.borderColor='#000000'; 
    this.style.color='#000000';
}

如果元素是由外部javascript脚本生成的,那么答案要复杂得多。您需要首先找到元素,因此by
id
class
方法将无法工作,除非它们已经有了一个-请参阅下面的
type
解决方案

查找方式
id

以下是首选项,您需要将id添加到输入提交中,例如
,以通过以下方式引用它:

// CHANGE SUBMIT STYLE
var foo = document.getElementById('submit');
foo.onmouseover = function() {this.style.borderColor='#000000'; this.style.color='#000000';}
foo.onmouseout = function() {this.style.borderColor='#888888'; this.style.color='#888888';}
foo.onclick = function() {this.style.borderColor='#000000'; this.style.color='#000000';}
但以下措施也应该起作用:

查找方式

在这种情况下,您需要指定一个类,例如
getElementsByClass
不查找
类型
,而是查找

<script type="text/javascript">

function getElementsByClass(node,searchClass,tag) {
  var classElements = new Array();
  var els = node.getElementsByTagName(tag);
  var elsLen = els.length;
  var pattern = new RegExp("\b"+searchClass+"\b");
  for (i = 0, j = 0; i < elsLen; i++) {
    if ( pattern.test(els[i].className) ) {
      classElements[j] = els[i];
      j++;
    }
  }
return classElements;
}

// CHANGE SUBMIT STYLE
var foo = getElementsByClass(document.body, 'submit', 'input')[0];
foo.onmouseover = function() {this.style.borderColor='#000000'; this.style.color='#000000';}
foo.onmouseout = function() {this.style.borderColor='#888888'; this.style.color='#888888';}
foo.onclick = function() {this.style.borderColor='#000000'; this.style.color='#000000';}

</script>
我要做的是:

<div id="externalElms">
    (<script> here)
</div>

(这里)

然后使用
var foo=getElementByType(document.getElementById('externalElms'),'submit','input')
,这样它就不必遍历页面上的每个元素。

感谢您的即时回复!我试过了,但没有效果。我是否可以使用“getElementByID”而不是“getElementByClass”,因为我建议这可能会导致问题?如果有帮助的话,它是“#HCB_comment_box input.submit”…因此,如果我理解正确的话,问题是没有为输入指定ID,
document.getElementByClass('input.submit')响应<代码>文档.getElementByClass('submit')行不通,对吧?现在越来越清楚了。我本来会为输入添加一个ID,然后使用document.getElementById方法,但输入本身是由外部JS脚本创建的。因此,我将不得不尝试另一种解决方案。谢谢你,大卫!另一个想法是:是否可以先在输入中附加一个ID(使用JS),然后通过文档调用它。getElementById?@Dan:添加了一个更快的选项,但是您需要在设置
ID
之前找到该元素,因此除非您需要使用
document.getElementById
再次访问它,否则可能不值得,大卫。我想我会让这一切继续下去。。。再见。
<div id="externalElms">
    (<script> here)
</div>