Str+='<tr>'+
'<td>'+aList[i].code+'</td>'+
'<td>'+aList[i].sname+'</td>'+
'<td>'+aList[i].rate01+'</td>'+
'<td>'+aList[i].rate02+'</td>'+
'<td>'+aList[i].new_prize+'</td>'+
'<td>'+aList[i].high+'</td>'+
'<td class="tl">'+aList[i].bak+'</td>'+ //关键代码,字符串拼接
'<td><a href="/update2.html?code='+aList[i].code+'' +
'" class="modify_btn" del_code="'+aList[i].code+'">' +
'<img src="images/star.jpg"> 修改</a></td>'+
'<td><input type="button" value="删除" stock_code="'+aList[i].code+'"></td>'+
'</tr>'
使用情景:
在做前后台交互时,经常会遇到这种情况,比如说,点击某个按钮,会跳转到另外一个网页,前端需要将按钮对应的某条数据传给后端,后端程序员根据前台传过来的数据进行操作,那么前端程序员怎么将这个数据传给后端?其实可以借助地址栏传参,通常我们常见到“http://index.html?number=7890”,其实问号后面就是参数。
jQuery中就是采用简单的字符串拼接,动态的向地址栏传入参数。如以上图中,a标签中的超链接的href属性中想要动态获取code参数,必须从将变量aList[i].code拼接进去,但是拼接要注意格式问题,因为href是属性,其外面必须要用双引号括起来,所以要写成这种形式‘+aList[i].code+’,这样得到结果还是变量,如果直接将aList[i].code直接写到双引号中去,解释器会直接将它当做字符串处理,达不到想要的效果。
二、vue.js中给URL传参数
<tr v-for="item in stock_list">
<td>{{item.code}}</td>
<td>{{item.sname}}</td>
<td>{{item.rate01}}</td>
<td>{{item.rate02}}</td>
<td>{{item.new_prize}}</td>
<td>{{item.high}}</td>
<td class="tl">{{item.bak}}</td>
<td><a v-bind:href="'update_vue1.html?code='+item.code" class="modify_btn"><img src="images/star.jpg"> 修改</a></td>
<td><input type="button" value="删除" @click="fnDel(item.code)"></td>
</tr>
与jQuery中不同,vue,js里面不能采取简单的字符串拼接来动态的给地址栏动态传入参数。
那么vue.js中怎么进行传参呢?
需要用到v-bind绑定,并且参数前面的额固定代码要用单引号括起来,然后与后面的参数进行拼接。