Javascript js不在IE上工作,但在FF上工作..给出inner.html错误..所以要转换为jquery格式
为什么这个javascript在Firefox中工作得很好,但在IE6和IE7中却不行(还没有检查IE8) 给出inner.html错误任何jquery专家都可以将整个代码转换成jquery吗?因为我已经在同一个站点上使用jquery进行其他操作了Javascript js不在IE上工作,但在FF上工作..给出inner.html错误..所以要转换为jquery格式,javascript,jquery,cross-browser,Javascript,Jquery,Cross Browser,为什么这个javascript在Firefox中工作得很好,但在IE6和IE7中却不行(还没有检查IE8) 给出inner.html错误任何jquery专家都可以将整个代码转换成jquery吗?因为我已经在同一个站点上使用jquery进行其他操作了 function twoDecPlaces(theValue) { var nm = new Number( Math.round( theValue * 100 ) ) /100 ; var parts = nm.toString().split
function twoDecPlaces(theValue) {
var nm = new Number( Math.round( theValue * 100 ) ) /100 ;
var parts = nm.toString().split( '.' );
var ord = new Number( parts[ 0 ] );
var dec = ( parts[ 1 ] ) ? parts[ 1 ] : '';
if( dec ){
dec = dec.toString().substring( 0, 2 );
ord += '.' + dec;
}
return( ord );
}
function fourDecPlaces(theValue) {
num = theValue;
result = num.toFixed(4);
return( result );
}
function isNumber(val)
{
if (isNaN(val))
{
return false;
}
if (val==0)
{
return false;
}
else
{
return true;
}
}
function doCalc()
{
if (isNumber(document.getElementById("num_shares").value))
{
var dividend_rate = document.getElementById('dividend_rate');
var currency = document.getElementById('currency').value;
var dividendValue = dividend_rate.options[dividend_rate.selectedIndex].value;
var num_shares = document.getElementById('num_shares');
num_shares = parseInt(num_shares.value);
var totalDividend = dividendValue * num_shares;
var valuePaid = document.getElementById('valuePaid');
var divpershare = document.getElementById('divpershare');
divpersharevalue = fourDecPlaces(dividendValue/1000);
divpersharevalue = divpersharevalue + " " + currency;
totalDividend = twoDecPlaces(totalDividend/100);
totalDividend = totalDividend + " " + currency;
valuePaid.style.display="";
divpershare.style.display="";
valuePaid.innerHTML = "<td>The total dividend paid was:</td><td align='right'>"+totalDividend+"</td>";
divpershare.innerHTML = "<td>The dividend per share was:</td><td align='right'>"+divpersharevalue+"</td>";
}
else
{
alert("Invalid entry in dividend box");
document.getElementById("num_shares").value="";
document.getElementById('valuePaid').innerHTML="";
}
}
函数的两个位置(值){
var nm=新数字(数学四舍五入(值*100))/100;
var parts=nm.toString().split('.');
var ord=新编号(零件[0]);
var dec=(第[1]部分)?第[1]部分:'';
国际单项体育联合会(12月){
dec=dec.toString()子字符串(0,2);
ord+='.+dec;
}
返回(ord);
}
函数四位(值){
num=该值;
结果=num.toFixed(4);
返回(结果);
}
函数isNumber(val)
{
if(伊斯南(瓦尔))
{
返回false;
}
如果(val==0)
{
返回false;
}
其他的
{
返回true;
}
}
函数doCalc()
{
if(isNumber(document.getElementById(“num_shares”).value))
{
var股息率=document.getElementById(“股息率”);
var currency=document.getElementById('currency')。值;
var dividendValue=股息率。选项[股息率。selectedIndex]。值;
var num_shares=document.getElementById('num_shares');
num_shares=parseInt(num_shares.value);
var TotalDistribution=dividendValue*num_股份;
var VALUEPADED=document.getElementById(“VALUEPADED”);
var divpershare=document.getElementById('divpershare');
divpersharevalue=四个十位(dividendValue/1000);
divpersharevalue=divpersharevalue+“”+货币;
总股息=两个小数点(总股息/100);
总股息=总股息+“”+货币;
valuePaid.style.display=“”;
divpershare.style.display=“”;
valuePaid.innerHTML=“支付的股息总额为:“+totaldivident+”;
divpershare.innerHTML=“每股股息为:“+divpersharevalue+”;
}
其他的
{
警报(“红利框中的无效条目”);
document.getElementById(“num_股份”)。value=“”;
document.getElementById('valuePaid')。innerHTML=“”;
}
}
任何jquery专家都可以将整个代码转换为jquery吗?Internet Explorer在编辑
表
、thead
、tbody
和tr
元素的内部HTML方面非常糟糕
使用标准DOM、替换整个表或替换单个单元格的内容。以下是我注意到的一些事情:
- 我不知道您为什么要使用两种不同的方法,一种用于
,另一种用于twoDecPlaces
函数fourdeecplaces
- 您不需要插入包含数据的表格单元格来显示结果。我只需要将文本放在表中(但隐藏),这样您就只需要更新值
如果您想将输入框限制为只允许在其中键入数字,那么有几个jQuery插件可用。这里有一个叫做。好的,有两件事需要改变。1) 不要将上面的函数放在
$(文档)的内部。ready(funtion(){…})
和2)从两个输出行和oops中删除style=“display:none;”“
。3)从isNumber
函数中删除额外的等号。。。我用了三个,但是当零是文本时就不行了。这是更新后的jsbin(),它正常工作,但是这个页面在IE上给出了js错误。请看这里,这只是一个jsbin代码错误,如果您在jsbin之外运行代码,它工作正常。或者,如果希望它在jsbin中工作,只需将这一行添加到HTML正文中,错误就会消失
<style type="text/css">
.text, .val { display: none; }
</style>
<table>
<tr id="valuePaid"><td class="text">The total dividend paid was:</td><td class="val"></td></tr>
<tr id="divpershare"><td class="text">The dividend per share was:</td><td class="val"></td></tr>
</table>
function twoDecPlaces(theValue) {
return theValue.toFixed(2);
}
function fourDecPlaces(theValue) {
return theValue.toFixed(4);
}
function isNumber(val) {
if (isNaN(val) || val == 0) { return false; }
return true;
}
function doCalc(){
if (isNumber($('#num_shares').val())) {
var currency = $('#currency').val();
var dividendValue = $('#dividend_rate').val();
var num_shares = parseInt($('#num_shares').val(),10);
var divpersharevalue = fourDecPlaces(dividendValue/1000) + " " + currency;
var totalDividend = twoDecPlaces((dividendValue * num_shares)/100) + " " + currency;
$('#valuePaid').find('.val').html(totalDividend);
$('#divpershare').find('.val').html(divpersharevalue);
$('.text, .val').show();
} else {
alert("Invalid entry in dividend box");
$('#num_shares').val('');
$('.text').hide();
$('.val').empty();
}
}