2014-04-10 38 views
11

这是我的代码 它在所有浏览器中工作都很完美但不是在Firefox中。.innerText为什么在Firefox中不起作用?

我尝试了很多东西,但根本没有工作。 请有人能帮我解决这个问题。 我做错了什么?

还有别的办法吗?

我正在使用.innerText因为价值从

<span class="jr-rating-wrapper-jr_stars-new-0"> 
4.5 
</span> 

未来有在控制台上没有错误。

<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> 
+0

你得到了什么错误? – pj013

+0

您是否在控制台中发现任何错误? – Andy

+0

此外,该代码的哪一部分不起作用。你有没有在其中加入断点来查看断点前的点? – Andy

回答

26

innerText是“旧Internet Explorer”的做法。

改为尝试textContent。理想情况下,您应该使用elem.textContent || elem.innerText,但是如果您使用的是jQuery,则可以执行jQuery("#the_id_here").text()

+0

已尝试,但无法正常工作 – user3474130

+0

@ user3474130请提供可帮助我们解决问题的反馈。要清楚,你的意思是'var PostStartone = document.getElementById('jr-rating-wrapper-jr_stars-new-0')。innerText || text.getElementById('jr-rating-wrapper-jr_stars-new-0')。textContent;'不工作,或者'$('#jr-rating-wrapper-jr_stars-new-0')。text() '不工作?这个答案提供了两个建议;如果你能够解释每个解决方案失败的原因,这将会很有帮助。 – apsillers

+0

@ user3474130你试过了吗?var PostStartone = document.getElementById('jr-rating-wrapper-jr_stars-new-0')。innerText || document.getElementById('jr-rating-wrapper-jr_stars-new-0')。textContent'如此答案中的建议?它没有工作吗? – apsillers

相关问题