琅琊榜高湛是好人坏人:javascript参数传递问题

来源:百度文库 编辑:神马品牌网 时间:2024/04/28 22:04:07
cell.innerHTML =<img border="0" src="../images/fo.gif"onclick="MM_openBrWindow('+material_count.value+')">
上面代码是用javascript代码添加一图片,图片有onclick()事件,material_count.value 是变量,请问要传递material_count.value和字符串"material"因该怎么写
最后得到的代码应该是MM_openBrWindow('1','material')
弄了一上午没搞定,请大家帮帮忙,
坏蛋 - 经理 四级 不行啊

<input type="text" name="material_count" id="material_count" size="45" value="试试">
<div id="cell"></div>
<script>
function MM_openBrWindow(a,b){
alert(a+"\n\n"+b);
}
var cell=document.getElementById('cell');
var material_count=document.getElementById('material_count');
cell.innerHTML='<img onclick=MM_openBrWindow("'+material_count.value+'","material") src="../images/fo.gif" border="0">';
alert(cell.innerHTML);
</script>

用window.open就可以,在open的页面中利用window.opener可以访问打开它的那个页面的变量,也就是window.opener.material_count.value