怎么点击URL然后调用这段JS

JavaScript013

怎么点击URL然后调用这段JS,第1张

试下这样行不行:

<a href="javascript:location.href = encodeURL('<%=request.getContextPath()%>/food/franchiser!ss.action?province=${dh.province}')"><%=request.getContextPath()%>/food/franchiser!ss.action?province=${dh.province}</a>

<a href="aaa.html?id=123" onclick="return LinkChange(this)">链接</a>

<script>

function LinkChange(v){

var url = v.href//得到链接的href

var value = url.split('?')//按?号分隔

if(value.length>1){ //如果URL里有参数

var newUrl = value[0] + "?" + value[1] + "456"//在这里加密你的Url参数,然后拼接

window.open(newUrl,"_self")

}

return false

}

</script>