1
甲新手問題而得到的變量, 我獲得從一個JSON一個變種通過這樣添加一個超鏈接到由JSON
$.each(json.Links,function(i,link)
一個cicle然後我將追加該變量使用此
$('#content').append('<br>').append(link);
內容
這工作,但我還希望添加到鏈接一個href,這樣當用戶點擊鏈接,他會直接到另一個頁面,但我不知道如何做到這一點
編輯:全HTML和腳本JS
<!DOCTYPE HTML>
<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="script.js"></script>
<title>Fake Delicious</title>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
</head>
<body>
<header>
<!-- Inserir banner -->
<h1>Delicious Testing Page</h1>
</header>
<div id="content">
coisa
</div>
</body>
</html>
腳本
var url="printTables.php?option=6";
$.getJSON(url,function(json)
{
$.each(json.Links,function(i,link)
{ var test="test"+i;
var but=$("<button>Show info</button>");
$(link).attr("href", link);
$('#content').append('<br>').append(link).append($('<div>').append(but));
});
})
在這個階段的按鈕不suposed做任何事情。鏈接,因爲我說這是正確的,因爲HTML顯示它正確我現在想要添加一個超鏈接到它的另一個頁面
我已經嘗試過,但它不起作用的HTML,我點擊鏈接,但沒有發生的事情 – user697110
你可以請你發佈你試過的代碼,以及生成的html。 –
這是相當多的代碼,但會做 – user697110