javascript 为什么 .innerText 在 Firefox 中不起作用?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22990812/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why is .innerText not working in Firefox?
提问by user3474130
Here is my code It's working perfect in all browsers but not in Firefox.
这是我的代码 它在所有浏览器中都能完美运行,但在 Firefox 中则不然。
I tried many thing but didn't work at all. Please can some one help me on this issue. Am I doing something wrong.?
我尝试了很多东西,但根本没有用。请有人帮助我解决这个问题。难道我做错了什么。?
Is there any other way.?
有没有别的办法。?
I'M USING .innerText because values are coming from
我正在使用 .innerText 因为值来自
<span class="jr-rating-wrapper-jr_stars-new-0">
4.5
</span>
There is no error on console.
控制台上没有错误。
<script type="text/javascript">
jQuery('#submitButton').click(function(){
var PostStartone = document.getElementById('jr-rating-wrapper-jr_stars-new-0').innerText;
var PostStarSec = document.getElementById('jr-rating-wrapper-jr_stars-new-1').innerText;
var PostStarThird = document.getElementById('jr-rating-wrapper-jr_stars-new-2').innerText;
var PostCapVal = document.getElementById('code').value;
var PostRBVal = "";
var selected = jQuery("div.jr_fieldDiv input[type='radio']:checked");
PostRBVal = selected.val();
jQuery.post("http://xyz/x/Update.php", {
GetStarOneValue : PostStartone ,
GetStarSecValue : PostStarSec ,
GetStarThirdValue : PostStarThird ,
GetCaptchValue : PostCapVal,
GetRadioBTNValue : PostRBVal});
});
</script>
回答by Niet the Dark Absol
innerText
is the "old Internet Explorer" way of doing it.
innerText
是“旧的 Internet Explorer”方式。
Try textContent
instead. Ideally you should use elem.textContent || elem.innerText
, but if you're using jQuery you can just do jQuery("#the_id_here").text()
.
试试吧textContent
。理想情况下,您应该使用elem.textContent || elem.innerText
,但如果您使用的是 jQuery,您可以只使用jQuery("#the_id_here").text()
.