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模式改变则不能 ...
随机推荐
- 洛谷P1582 倒水 二进制的相关应用
https://www.luogu.org/problem/P1582 #include<bits/stdc++.h> using namespace std; long long N,K ...
- 无缘诺贝尔奖的George Dantzig——线性规划之父
无缘诺贝尔奖的George Dantzig——线性规划之父 王军强,2012年11月2日 “线性规划之父”的George Dantzig,与“计算机之父”.“博弈论之父”John Von Neuman ...
- (转)java垃圾回收二
转自:http://shuaijie506.iteye.com/blog/1779651 在网上看到一篇不错的文章,记录下来备忘. 要理解java对象的生命周期,我们需要要明白两个问题, 1.java ...
- ubuntu19.04 配置远程连接ssh
安装ssh-server sudo apt install openssh-server 参照:https://baijiahao.baidu.com/s?id=1631505486531979316 ...
- jsp中的javascript的$(document).ready( function() { $("#loginForm").validate()
转自:https://bbs.csdn.net/topics/392459787?list=71147533 下面是jsp页面中的JavaScript代码 $(document).ready( fun ...
- shell 预定义变量
echo "上一次后台pid is $!"echo "当前进程pid is $$"echo "last command return code is ...
- AcWing 789. 数的范围 二分+模板
https://www.acwing.com/problem/content/791/ #include<bits/stdc++.h> using namespace std; ; int ...
- 「hdu 4845 」拯救大兵瑞恩 [CTSC 1999](状态压缩bfs & 分层图思想)
首先关于分层图思想详见2004的这个论文 https://wenku.baidu.com/view/dc57f205cc175527072208ad.html 这道题可以用状态压缩,我们对于每一把钥匙 ...
- mysql分组,然后组内排序取最新的一条
参照: https://blog.csdn.net/qq_16504067/article/details/78589232 https://www.cnblogs.com/w1441639547/p ...
- 【转】Java8 Stream 流详解
当我第一次阅读 Java8 中的 Stream API 时,说实话,我非常困惑,因为它的名字听起来与 Java I0 框架中的 InputStream 和 OutputStream 非常类似.但是 ...