欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

js獲取form表單中name屬性的值

 更新時(shí)間:2019年02月27日 15:50:59   作者:踩坑的土撥鼠  
今天小編就為大家分享一篇關(guān)于js獲取form表單中name屬性的值,小編覺(jué)得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來(lái)看看吧

在項(xiàng)目中因?yàn)閯?dòng)態(tài)表單無(wú)法確定標(biāo)簽name屬性的值,因此需要即時(shí)獲取以便進(jìn)行存儲(chǔ)。前端代碼如下:

<div class="control-group">
<label class="control-label">土撥鼠常挖坑</label>
<form:input path="formAttribute1" class="input-xlarge" value="" name="測(cè)試1"/></div>
<form:input path="formAttribute1" class="input-xlarge" value="" name="測(cè)試2"/></div>
<form:input path="formAttribute1" class="input-xlarge" value="" name="測(cè)試3"/></div>

1、attr:$("#formAttribute1").attr("name");然后得到的值是formAttribute1(有沒(méi)有前輩能給我講講為什么呀)

2、prop:?jiǎn)栴}同上

3、在上述兩種方式都失敗后,整個(gè)人不行了。最后找到了一個(gè)相對(duì)可行的方式,對(duì)class屬性做修改,獲取全部值,然后通過(guò)<c:foreach>標(biāo)簽獲取this.value  和this.name,并放入map中。具體操作可參考如下代碼(與上面代碼區(qū)別在于class屬性,在此處添加了property作為標(biāo)識(shí),此處可自定義名稱)

<div class="control-group">
<label class="control-label">土撥鼠常挖坑</label>
<form:input path="formAttribute1" class="input-xlarge property" value="" name="測(cè)試1"/></div>
<form:input path="formAttribute1" class="input-xlarge property" value="" name="測(cè)試2"/></div>
<form:input path="formAttribute1" class="input-xlarge property" value="" name="測(cè)試3"/></div>

JS方法如下:

<script type="text/javascript">
   $("#btnSubmit").on("click",function () { //事件綁定btnSubmit是信息填寫(xiě)完畢提交處的按鍵
     var propertyMap= {};
     $(".property").each(function () {
       propertyMap[this.name] = this.value;
     });
    var propertyInfo= JSON.stringify(propertyMap);
     alert($("#propertyInfo")
   });
 </script>

總結(jié)

以上就是這篇文章的全部?jī)?nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,謝謝大家對(duì)腳本之家的支持。如果你想了解更多相關(guān)內(nèi)容請(qǐng)查看下面相關(guān)鏈接

相關(guān)文章

最新評(píng)論