在我的.jsp文件中,我有这样的代码(要点)
<td width="200px">
<input type="text" id="${general.pk.code }_${MTPL[4].pk.run}"
name="${general.pk.code }_${MTPL[4].pk.run}"
value="${MTPL[4].value}" onChange="gg('${MTPL[4].jsCode }','${MTPL[4].pk.code }',this,'${MTPL[4].operator }','${MTPL[4].param1 }','${MTPL[4].param2 }','${MTPL[4].param3 }','${MTPL[4].param4 }','${MTPL[4].param5 }','${MTPL[4].pk.run }','${MTPL[4].param6 }','${MTPL[4].param7 }')"
style="text-align: right;">
</td>
<c:forEach items="${valueRun }" var="generalR">
<td width="200px">
<input type="text" id="${general.pk.code }_${generalR}"
name="${general.pk.code }_${generalR}"
value="" onChange="gg('${MTPL[4].jsCode }','${MTPL[4].pk.code }',this,'${MTPL[4].operator }','${MTPL[4].param1 }','${MTPL[4].param2 }','${MTPL[4].param3 }','${MTPL[4].param4 }','${MTPL[4].param5 }','${MTPL[4].pk.run }','${MTPL[4].param6 }','${MTPL[4].param7 }')"
style="text-align: right;">
</td>
</c:forEach>当页面完成加载时,值如下(检查元素)
输入type=“文本”“id="MTPL_4”name="MTPL_4“MTPL_4”1100“onchange="gg('COPAS','MTPL_4',this,'','this','','4','4','',‘style=’‘)文本-对齐:右”>;
我想在javascript文档中获取函数gg()上的参数。如何做到这一点。
<script>
$(document).ready(function() {
var a = $("#MTPL_4").val(param1); //didnt get param1 value
});
</script>我尝试了.val(),但它只获得了值(1100)。如何在函数gg();中获取值(尝试获取"COPAS“、'MTPL_4‘等)
发布于 2017-02-01 07:36:52
为此,您可以使用jquery方法,然后从其中提取子字符串,如下所示:
$(document).ready(function(){
var len = $("#MTPL_4").attr("onchange").length;
alert($("#MTPL_4").attr("onchange").substring(3, len-1));
})此外,如果要拆分字符串并获取由“”分隔的单个参数,则可以使用拆分方法。
https://stackoverflow.com/questions/41974066
复制相似问题