js遍历传参给html
<p id="subp" hidden><button id= "upsub"shiro:hasPermission="sys:menu:edit" type="button" class="btn btn-success" onclick="updateById('@params_id@')">
<i aria-hidden="true"></i>修改
</button>
<button id= "delsub" shiro:hasPermission="sys:menu:del" type="button" class="btn btn-danger" onclick="delById('@params_id@')">
<i aria-hidden="true"></i>删除 </button>
<button id= "findsub" shiro:hasPermission="sys:menu:view" type="button" class="btn btn-info" onclick="findById('@params_id@')">
<i aria-hidden="true"></i>查看
</button>
</p>
JS:
//html() 方法返回或设置被选元素的内容 (inner HTML)。如果该方法未设置参数,则返回被选元素的当前内容。
var buttonHtml = $("#subp").html();
//split() 方法用于把一个字符串分割成字符串数组,查看有几个button
var buttoum = (buttonHtml.split('<button')).length-1;
for(var m=0;m<buttoum;m++){
//遍历按钮个数,取出@params_字符串的位置,进行替换,直至没有为止,indexOf()可返回某个指定的字符串值在字符串中首次出现的位置
var startm = buttonHtml.indexOf('@params_');
//不存在,则不需要进行下面操作
if(startm>=0){
var endm = buttonHtml.indexOf('@\')');
//substring() 方法用于提取字符串中介于两个指定下标之间的字符
var iteme = buttonHtml.substring(startm,endm+1);
//将字符串@params_id@替换,replace() 方法用于在字符串中用一些字符替换另一些字符,或替换一个与正则表达式匹配的子串
buttonHtml = buttonHtml.replace(iteme,""+menuList.subModuleList[k].id+"")
}else{
break;
}
}
html += buttonHtml;
主要方法:
split()分割字符串数组
indexOf()返回标志首次出现的位置
substring()提取两个指定下标之间的字符
replace()字符替换
js遍历传参给html的更多相关文章
- js遍历传参到html
<p id="subp" hidden><button id= "upsub"shiro:hasPermission="sys:me ...
- EL表达式的js函数传参问题
<!Doctype html> <html> <head> <title>js的传参问题</title> <script type=& ...
- js url传参,参数加密
前台 function encode64(input) { var output = ""; var base = new Base64(); var output = base. ...
- js构造函数传参
1.直接传参并用this关键字初始化属性 function Person(name,age,learn){ this.name = name; this.age = age; this.learn = ...
- js get 传参 汉字 乱码问题
js encodeURI(encodeURI(searchWord)) java URLDecoder.decode(searchWord,"utf-8")
- 用js来传参到父网页实现
今天搞了半天,用location.href提交参数到后台,结果php无法接收到参数,这让我找了半天,终于发现原因是本页被另外的主页引用了,最终发现问题出在提交js上,最终用parent.locatio ...
- js SetTimeout传参问题
今天写代码遇到这样一个问题,先上代码 <!--JS方法--> function textout(obj){ if(opac==60){opac=0;return;}; opac+=10; ...
- JS 内部传参
- tp5中url使用js变量传参方法
window.location.href="{:url('Index/index')}>"+"/ID/"+ID; //这样可以生成,但url模式改变则不能 ...
随机推荐
- shell编程基础知识
什么是shell shell是一个命令解释器,它在操作系统的最外层,负责直接与用户对话,把用户的输入解释给操作系统,并处理各种各样的操作系统的输出结果,输出屏幕返回给用户 shell对话方式 交互的方 ...
- 使用Python发送、订阅消息
使用Python发送.订阅消息 使用插件 paho-mqtt 官方文档:http://shaocheng.li/post/blog/2017-05-23 Paho 是一个开源的 MQTT 客户端项目, ...
- 【Python】循环的拓展
- 训练20191007 2017-2018 ACM-ICPC Latin American Regional Programming Contest
2017-2018 ACM-ICPC Latin American Regional Programming Contest 试题地址:http://codeforces.com/gym/101889 ...
- socks5代理服务器搭建
1.首先,编译安装SS5需要先安装一些依赖组件 yum -y install gcc gcc-c++ automake make pam-devel openldap-devel cyrus-sasl ...
- 调用系统计算器n次
#define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<stdlib.h> void main1(){ int n ...
- js -- 日期时间格式化
/** * js日期时间格式化 * @param date 时间读对象 * @param format 格式化字符串 例如:yyyy年MM月dd日 hh时mm分ss秒 * @returns {stri ...
- MySql -- default 默认约束
常用数据库约束: 一.default 默认约束: 二.not null:非空约束,指定某列不为NULL: 三.unique:唯一约束,指定某列和几列组合的数据不能重复: 四.primary key:主 ...
- IntelliJ IDEA 2017.3尚硅谷-----配置 Maven
- Android开发实战——记账本(5)
开发日志——(5) 今天打算将图标的功能实现,将打开图表的选项放在右上方,所以重写MainActivity中的onOptionsItemSelected方法.增添Chart选项 public ...