0
我正在使用.net在此項目上工作。當你瀏覽瀏覽器時,你會看到五個不同的餐廳,下面的按鈕說要改變顏色,如果你點擊它,你可以改變它。我想要做的是在餐廳的名字旁邊有地址,電話號碼,但我真的不知道如何編碼。我確信我會這樣做,但我的想法是不記得如何去做。下面是我的代碼..如何爲輸出添加代碼
這裏是我的類代碼:
Public Class Restaurant
Private _Id As Integer
Public Property Id() As Integer
Get
Return _Id
End Get
Set(ByVal value As Integer)
_Id = value
End Set
End Property
Private _Name As String
Public Property Name() As String
Get
Return _Name
End Get
Set(ByVal value As String)
_Name = value
End Set
End Property
Private _Location As String
Public Property Location() As String
Get
Return _Location
End Get
Set(ByVal value As String)
_Location = value
End Set
End Property
Private _Stars As Integer
Public Property Stars() As Integer
Get
Return _Stars
End Get
Set(ByVal value As Integer)
_Stars = value
End Set
End Property
Private _PhoneNumber As Integer
Public Property PhoneNumber() As String ' Allows "-", ".", "x" in number
Get
Return _PhoneNumber
End Get
Set(ByVal value As String)
_PhoneNumber = value
End Set
End Property
Public Sub Restaurant()
End Sub
''' <summary>
''' This Function simulates getting data from a Database
''' </summary>
''' <returns></returns>
''' <remarks></remarks>
Public Function GetFavoriteRestaurants() As List(Of Restaurant)
Dim favRestaurants As List(Of Restaurant) = Nothing
favRestaurants = New List(Of Restaurant)
favRestaurants.Add(New Restaurant)
favRestaurants(0).Id = 0
favRestaurants(0).Name = "Carabbas"
favRestaurants(0).Location = "North Canton"
favRestaurants(0).Stars = 3
favRestaurants(0).PhoneNumber = 330 - 966 - 242
favRestaurants.Add(New Restaurant)
favRestaurants(1).Id = 1
favRestaurants(1).Name = "Peter Shears"
favRestaurants(1).Location = "Canton"
favRestaurants(1).Stars = 4
favRestaurants(1).PhoneNumber = 330 - 522 - 8300
favRestaurants.Add(New Restaurant)
favRestaurants(2).Id = 2
favRestaurants(2).Name = "Salsitas"
favRestaurants(2).Location = "Kent"
favRestaurants(2).Stars = 2
favRestaurants(2).PhoneNumber = 330 - 673 - 8874
favRestaurants.Add(New Restaurant)
favRestaurants(3).Id = 3
favRestaurants(3).Name = "Ruby Tuesday"
favRestaurants(3).Location = "North Canton"
favRestaurants(3).Stars = 4
favRestaurants(3).PhoneNumber = 330 - 434 - 232
favRestaurants.Add(New Restaurant)
favRestaurants(4).Id = 4
favRestaurants(4).Name = "OutBack SteakHouse"
favRestaurants(4).Location = " Canton"
favRestaurants(4).Stars = 4
favRestaurants(4).PhoneNumber = 330 - 493 - 9515
Return favRestaurants
End Function
End Class
這裏是我的其他代碼:
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Default.aspx.vb" Inherits="RestaurantVB._Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Lab W8</title>
<script language="javascript" type="text/javascript">
//I built in some of our HTML5 code from last week
function browserHtml5Test() {
var canvas = document.getElementById("html5Test");
if (canvas == null || canvas.getContext == null) {
document.getElementById("canvasReport").style.color = "Red";
document.getElementById("canvasReport").innerHTML = "HTML5 NOT Supported";
}
document.getElementById("canvasReport").innerHTML = "HTML5 Supported!";
}
function changeStyles() {
//Get the Id of this particular item. Here we don't have to change the styles.
//We could make a call to a database via ajax since we have the id that is stored
//in the database.
var tmp = document.getElementById("rest0");
if (tmp != null) {
tmp.style.color = "green";
}
tmp = document.getElementById("rest1");
if (tmp != null) {
tmp.style.color = "green";
}
tmp = document.getElementById("rest2");
if (tmp != null) {
tmp.style.color = "green";
}
tmp = document.getElementById("rest3");
if (tmp != null) {
tmp.style.color = "green";
}
tmp = document.getElementById("rest4");
if (tmp != null) {
tmp.style.color = "green";
}
tmp = document.getElementById("rest5");
if (tmp != null) {
tmp.style.color = "green";
}
//Yes these could have been done via loop.
}
</script>
<style type="text/css">
#TextArea1
{
width: 244px;
}
#Select1
{
width: 226px;
}
#Text1
{
width: 151px;
}
</style>
</head>
<body onload="browserHtml5Test();" style="height: 340px">
<form id="form1" runat="server">
<div id="canvasReport" style="color: Blue; margin-bottom: 15px;"></div>
<div>
<%
For Each r As RestaurantVB.Restaurant In _restaurants
Response.Write(String.Format("<div id=""rest{0}"">{1}</div>", r.Id, r.Name))
Next
%>
<br />
<br />
<br />
<input type="button" value="Change Styles" onclick="changeStyles();" /></div>
<canvas id="html5Test」 width="150" height="150"></canvas>
</form>
</body>
</html>
我的問題是有人可以幫助我瞭解如何編寫手機餐廳旁邊的號碼和地址,以便他們全都出現。
嘗試在提問時將代碼減少到基本部分。 – Jan