2010-09-10 53 views
0

下面的代码我不能工作(jquery 1.4.2) 看起来选择器不工作,因为它不会在id = p_quantity之后做任何事情。我添加了.remove()来查看它是否是该行的麻烦,并且它没有删除兼容模式下的文本框,它以常规模式和FF工作。难倒!jquery代码无法在IE8兼容模式下工作

编辑此行不起作用。

$("input[type='textbox'][name^='QTY']").attr('id','p_quantity').remove(); 

有趣的是两个图像输入的第二撤除IE COMP模式下工作精细

<table cellspacing="0" cellpadding="3" border="0"><tr><td> 
<span class="PageText_L71n">Qty</span>: <input type="textbox" name="QTY.LL24" size="3" maxlength="7" onkeydown="javascript:QtyEnabledAddToCart();" value="1"> 
</td><td> 

          <input type="image" src="/v/vspfiles/templates/moderntot/images/buttons/btn_addtocart.gif" name="btnaddtocart" alt="Add to cart" border="0"> 

    <input type="hidden" name="ReplaceCartID" value="" /> 
    <input type="hidden" name="ProductCode" value="LL24" /> 
    <input type="hidden" name="e" value="" /> 

     <input type="hidden" name="ReturnTo" value="ShoppingCart.asp" /> 

    &nbsp;<input type="image" src="/v/vspfiles/templates/moderntot/images/buttons/btn_addtowishlist.gif" name="btnaddtowishlist" alt="Add To Wish List" border="0" /> 

    </td></tr> 

    </table> 

<script type="text/javascript" language="javascript"> 
$(function(){ 
$("input[type='textbox'][name^='QTY']").attr('id','p_quantity').remove(); 
$("input[type='image'][name^='btnadd']").attr('id','button').remove();  
}); 
</script> 

回答

1

不能更改现有形式的输入元件的idname attribtues在IE6/7 。您需要创建一个全新的DOM元素并将其替换为原始元素。另请参阅此related question

顺便说一句,textbox是一个无效的输入类型,它将默认为text。你实际上应该使用type="text"

+0

好吧,我不知道怎么说也引起第二jQuery的输入语句工作正常BTW,这并不正常工作或$(“输入[类型=‘文本’] [名^ =‘数量’]”)。删除();它没有改变任何属性 – user357034 2010-09-10 16:14:59

+0

好吧,你是正确的,但不是关于在这种情况下的第一件事,而是关于“文本框”(这段代码不是我不能改变的)它有“文本框”作为类型,所以我改变了选择器为$(“input [type^='text'] [name^='QTY']”)。remove();它可以正常工作 – user357034 2010-09-10 16:27:40

+1

它确实无法工作。尝试在JS/jQuery中选择带有新ID或名称的元素,或者将表单提交给服务器端,而服务器端又依赖新名称作为参数名称。 – BalusC 2010-09-10 16:29:55