0

我有以下 javascript 函数。

           function formsubmit()
            {
              var missedReasonCode =$('input[name*="MissedReasonCode"]').map(function()     
           {return $(this.id).val();}).get().join("/") ;
              $("#reasonValue").val(missedReasonCode); 
         alert($("#reasonValue").val());--able to get the list of values as in the format say /a/b/c  
            document.getElementById("frm1").submit();
                  }

        ***and the below is the part of the jsp page code:***


                <form:textarea path="reasonValue"  id="reasonValue" cssClass="textbox width100" cssStyle="visibility:hidden"></form:textarea>                

                </form:form>

             <div id="mask" style="display: none;"></div>

            <div id="adddelTBSec" class="adddelTBSection" style="display: none;">
          <div class="line marT20">Missed Reason Code</div>
         <div class="line">


             <div class="unit width60 padR10 boxSizing marT5">

             <input type="text"  name="MissedReasonCode" maxlength="150" size="50"               value="" class="padR10 boxSizing"/>

                   </div>

      <div class="unit icoPlus marT5" onclick="adddelTBSection(this,   'adddelTBContainer',1)"></div>
    <div class="unit marL10 icoMinus marT5" onclick="adddelTBSection(this,   'adddelTBContainer', 0)"></div>
</div>
             </div>



                 <div id="addNewMisdReasonCode" class="ltBox" style="display: none;">
             <div>
                <div class="ltBoxHdr">
                  Add New "Missed Reason Codes"
                  </div>
             <div class="ltBoxContent" style=" width: 640px;">
                    <div id="adddelTBContainer" style="maxheight:200px;overflow:auto;">  
                        <div>
                          <div class="line">Missed Reason Code</div>
                          <div class="line">


                    <div id="clear" class="unit width60 padR10 boxSizing marT5">
                     <input type="text"  name="MissedReasonCode"           value=""  maxlength="150" size="50"  class="padR10 boxSizing"/>
                    </div>
         <div class="unit icoPlus marT5" onclick="adddelTBSection(this, 'adddelTBContainer', 1)"></div>
                </div>
                </di v>
            < /div>

代码获取值列表并在表单提交时保存到数据库中,我能够获取值列表并保存在数据库中,例如 /a/b/c

但我想摆脱这个最初的特殊字符 / ,任何帮助表示赞赏

4

2 回答 2

0

从你的 jsp 代码中准确判断有点困难,但我猜你有一块 HTML 充当每个新添加项目的模板,即逻辑上你有这样的 html 块:

  • 新项目模板(隐藏)
  • 项目a
  • b项
  • c项
  • ...

因此,您的$('input[name*="MissedReasonCode"]')选择器正在抓取(空)模板项 2,它被添加到映射字符串的前面,因此初始/. 所以你有两个选择:

  1. 修复您的选择器以仅包含“真实”项目(通过忽略隐藏项目或使用基于真实项目周围容器的更具体的选择器)
  2. 制作映射字符串后,/substring(ie missedReasonCode.substring(1);)修剪首字母
于 2013-09-20T05:19:18.427 回答
0

"/"你必须用.slice()这种方式取出第一个:

$("#reasonValue").val(missedReasonCode.slice(1));
//--------------------^^^^^^^^^^^^^^^^^^^^^^^^^--try using this way

从文档:

给定一个表示一组 DOM 元素的 jQuery 对象,.slice() 方法构造一个新的 jQuery 对象,其中包含由 start 和可选的 end 参数指定的元素的子集。提供的起始索引标识集合中元素之一的位置;如果 end 被省略,则该元素之后的所有元素都将包含在结果中。

于 2013-09-20T05:21:44.287 回答