Javascript在c#web浏览器中的作用不同

Javascript在c#web浏览器中的作用不同,javascript,c#,Javascript,C#,在InternetExplorer中,我正在尝试一个代码,它工作得很好,在c#中运行它时,它不会改变我让它操作的对象的宽度。代码非常简单: function fixstyles(){ if(document.getElementsByClassName('x-grid-header-row')[1].children.length > 10){ alert('ye'); vv = document.getElementsByClassName('x-grid-header-row').le

在InternetExplorer中,我正在尝试一个代码,它工作得很好,在c#中运行它时,它不会改变我让它操作的对象的宽度。代码非常简单:

function fixstyles(){
if(document.getElementsByClassName('x-grid-header-row')[1].children.length > 10){
alert('ye');
vv = document.getElementsByClassName('x-grid-header-row').length -1;
alert(document.getElementsByClassName('x-grid-header-row')[vv].getElementsByTagName('th')[0].style.width);
document.getElementsByClassName('x-grid-header-row')[vv].getElementsByTagName('th')[0].style.display = 'none !important'; // checkbox
document.getElementsByClassName('x-grid-header-row')[vv].getElementsByTagName('th')[7].style.width = '0px !important'; // checkbox
 }
它会显示“24px”警报,不执行任何其他功能,但是,当我在internet explorer中以本机方式运行相同的精确代码时,它工作正常


有什么想法吗?

这个问题没有意义,JavaScript不能在“C”中运行。我假设您是从C#将JS注入浏览器,但我没有看到任何代码表明答案不完整或您不完全理解问题。@James注入方法不是必需的,因为我已经提到我看到了警报,因此,代码被成功注入,唯一的问题是上面列出的代码。这可能是缓存问题。尝试在IE中启动网站时清除缓存,并在本机浏览器上清除缓存。我也遇到过这些问题,发现这只是一个浏览器缓存问题。