2012-07-04 64 views
1

当我尝试从页面加载使用jquery的表单属性中获取值我正在获取Java脚本错误,“对象不支持此属性或方法“。让我知道这个问题。对象不支持此属性或方法错误Jquery

alert($("[name=searchAttribute.brand.attributeValue]").val()); 

我使用的是struts2和Jquery。 内部行动我有searchAttribute作为ValueObject属性在这里我有品牌作为另一个,它内部它有attributeValue作为另一个属性。

我需要在页面加载时根据此值加载下拉列表。

<script type="text/javascript"> 
    $(document).ready(
      function() { 

      fetchDropDownValues($("#idGMMHouse").val(),'<s:property value="brandloadUrl"/>','idGMMBrand','idGMMLine'); 
      var fieldname = ''; 


       alert($("[name="+ 'searchAttribute.brand.attributeValue' +"]").val()); 

      }); 
</script> 


<tr> 
        <td width="80px"><s:text name="filter.price.gmmhouse" /></td> 
        <td width="1px"><s:text name="filter.colon" /></td> 
        <td width="270px"> <s:select cssClass="drop" tabindex="1" 
         listKey="code" listValue="value" headerKey="0" 
         headerValue="Select One" 
         onchange="fetchDropDownValues(this.value,'%{brandloadUrl}','idGMMBrand','idGMMLine');" id="idGMMHouse" 
         name="searchAttribute.house.attributeValue" list="lstGMMHouse"></s:select></td> 
        <td width="80px"><s:text name="filter.price.gmmbrand" /></td> 
        <td width="1px"><s:text name="filter.colon" /></td> 
        <td width="160px"><s:url action="loadGMMLineDropDown" 
         id="lineloadUrl"></s:url><s:select cssClass="drop" tabindex="1" 
         id="idGMMBrand" 
         onchange="fetchDropDownValues(this.value,'%{lineloadUrl}','idGMMLine');" 
         headerKey="0" headerValue="Select One" 
         name="searchAttribute.brand.attributeValue" list="{}"></s:select></td> 
        <td width="80px"><s:text name="filter.brand.desc" /></td> 
        <td width="1px"><s:text name="filter.colon" /></td> 
        <td width="270px"><s:select cssClass="drop" tabindex="1" 
         id="idGMMLine" headerKey="0" headerValue="Select One" 
         name="searchAttribute.line.attributeValue" list="{}"></s:select></td> 
        <td align="LEFT">&nbsp;</td> 
       </tr> 
+0

发布你的'html'和'js'代码相关的问题 – thecodeparadox

+0

你可以试试'$(“input [type = select] [name ='searchAttribute.brand.attributeValue']”)'? – MilkyWayJoe

+0

现在错误发生时,我把它作为警报($(“[name ='searchAttribute.brand.attributeValue']”)。val());但我无法获得价值。它只显示0. – Jothi

回答

0

你使用的是什么版本的jQuery?如果它是1.7.2,我认为它不再支持[name = whatever]语法。我一直在使用jQuery/Sharepoint进行一些SharePoint开发,并且在用类似标记解析xml时遇到这个问题。尝试使用.filter()方法来代替你所需要的。

+0

尽情享受吧:http://api.jquery.com/attribute-equals-selector/ –

0

jQuery的$选择器总是返回一个DOM元素数组,即使选择器本身只匹配一个元素。所以你应该遍历这些元素,或者如果你确定只有其中一个元素,那么你可以通过向你的选择器添加一个[0]数组索引来引用它。

val()函数只能在单个DOM元素上解释,而不能在数组上解释。

所以这

alert($("[name=searchAttribute.brand.attributeValue]")[0].val()); 

应该解决您的问题 - 当然,你应该检查数组的长度,并确保没有在它至少一个元素,它引用了第一个元素之前。

+0

无论如何它[应该工作](http://jsfiddle.net/MdsZX/)。 –

+0

@AymanSafadi我不得不承认这令我吃惊。很高兴知道,谢谢。 –

相关问题