zoukankan      html  css  js  c++  java
  • JS中的替换,以及替换指定位置的字符串

    批量修改name属性中的值

     // 渲染完成,开始修改ansewer的name属性
                                 $('.sub_timu_zong_tihao').each(function(i){
                                    $(this).find('input[name*=bianhao]').each(function(){
                                        // 首先获取name的值,对
                                        console.log('正在修改bianhao')
                                        var old=$(this).attr('name')
                                        var now=old.replace('bianhao',i)
                                        $(this).attr('name',now)
                                    })
    
                                })
    

    修改题目的编号

     function shuaxin_tihao(){
                                        // 渲染完成,开始修改name中的tihao
                                    $('.sub_timu_zong_tihao').each(function(i){
                                        $(this).find('input[name*=tihao]').each(function(){
                                            // 首先获取name的值,对
                                            console.log('正在修改input中的tihao')
                                            var old=$(this).attr('name')
                                            var now=old.replace('tihao',i)
                                            $(this).attr('name',now)
                                        })
    
                                        $(this).find('textarea[name*=tihao]').each(function(){
                                            // 首先获取name的值,对
                                            console.log('正在修改textarea中的tihao')
                                            var old=$(this).attr('name')
                                            var now=old.replace('tihao',i)
                                            $(this).attr('name',now)
                                        })
    
                                        $(this).find('*[id*=tihao]').each(function(){
                                            // 首先获取name的值,对
                                            console.log('正在修改id中的tihao')
                                            var old=$(this).attr('id')
                                            var now=old.replace('tihao',i)
                                            $(this).attr('id',now)
                                        })
    
                                    })
                            }
    

    由于第一次是根据名字进行替换,这次进行替换,已经没有名字了。所以,这时候,根据位置去替换

    根据位置替换字符

    //str:原始字符串,index,开始位置,changeStr,改变后的字
    function changeStr(str,index,changeStr){
    	 return str.substr(0, index) + changeStr+ str.substr(index + changeStr.length);
    	 }
    //记住的,传值的时候,第三个要传字符串
       var str="row[answer5][tihao]"
         var a=changeStr(str,13,'1')
         console.log(a)
    

    在php生成页面的时候,就确定每个tihao的替换位置

  • 相关阅读:
    GIS有关GP服务的发布和调用
    博文列表
    VCL编写笔记整理
    Delphi操作Excel(Use Oel)
    使用 ImageEnView 给图片加水印,及建缩略图
    Delphi下MSMQ(Mircosoft Message Queue)实例(私有队列)
    从给定字符串中截取n个字节的字符(解决汉字截取乱码问题)
    tbytes 转 十六进制 string
    Delphi中拖动的方式来移动TPageControl的Tab
    delphi TEdit透明
  • 原文地址:https://www.cnblogs.com/cn-oldboy/p/13198161.html
Copyright © 2011-2022 走看看