點(diǎn)擊沒反應(yīng)?
<script type="text/javascript">
var main = document.body;
//創(chuàng)建鏈接
function createa(url,text)
{
? ?var input=document.createElement("input");
? input.type="button";
? input.value=text;
? input.setAttribute("onclick","javascript:window.open(url)");
? main.appendChild(input); ??
}
createa("http://idcbgp.cn/","慕課網(wǎng)");// 調(diào)用函數(shù)創(chuàng)建鏈接
</script>?
什么問題呢
2015-08-01
萬分感謝??!
2015-05-29
這個(gè)是因?yàn)槟愫瘮?shù)的參數(shù)url的作用域是在函數(shù)里面,而javascript:window.open(url)里面url獲取的是全局的url變量,這個(gè)全局的url變量你沒有定義,你只在函數(shù)里定義了url,自然他彈不出來窗口了。
在你的var main = document.body;下面加一行:var gURL = "" ;?
然后在你的函數(shù)function里面的第一行加上 gURL = url ;?
最后把你javascript:window.open(url)換成javascript:window.open(gURL),應(yīng)該就可以了 。
為了防止弄不清楚,把代碼給你貼上來....
<script type="text/javascript">
var main = document.body;
var gURL = "" ;?
//創(chuàng)建鏈接
function createa(url,text)
{
????gURL = url ;?
????var input=document.createElement("input");
????input.type="button";
????input.value=text;
????input.setAttribute("onclick","javascript:window.open(gURL)");
????main.appendChild(input); ??
}
createa("http://idcbgp.cn/","慕課網(wǎng)");// 調(diào)用函數(shù)創(chuàng)建鏈接
</script>?