3月 21, 2014

MVC 比較特別要注意的用法

<label for="CheckBox1">CheckBox1</label><br>
@Html.Label("CheckBox1")
<br>
<a href="/" id="link1" target="_Blank">thisislink</a><br>
@Html.ActionLink("thisislink","index" , null, new { id="link1",target="_Blank"})
<br>
<a href="@Url.Content("http://google.tw")" target="_blank"><img alt="" src="logo_s.gif" /></a>
<br>
就只是按鈕:<input id="Button1" type="button" value="button" /><br>
水平線: <hr /><br>

3月 20, 2014

MVC Html對照

 @Html.Label("CheckBox:")<br>
    <input id="Checkbox1" name="group1" type="checkbox" value="yes" checked="checked"/>yes
    @Html.CheckBox("group1",false,new {id="Checkbox2",value="no"})
    <label for="checkbox1">no</label>
    <br>
    @Html.Label("RadioButton:")<br>
    <input id="RadioButton1" name="group2" type="radio" value="man"/>man
    @Html.RadioButton("group2","female", true, new { id="rd1"})female
    <br>
    @Html.Label("Textbox:")<br>
    First name: <input id="textbox1" name="name" type="text" value=""><br>
    Last name:  @Html.TextBox("name", "", new {id="textbox2" })
    <br>
    @Html.Label("Password:")<br>
    Password: <input id="password1" name="pwd" type="password">
    confim Password:@Html.Password("pwd", "", new {id="password2" })
    <br>
    @Html.Label("Hidden:")<br>
    <input id="Hidden1" name="hide" type="hidden" value="text" />
    @Html.Hidden("hide", "text", new { id="Hidden2"})
    <br>
    @Html.Label("TextArea:")<br>
    <textarea cols="20" id="TextArea1" name="TextArea1" rows="2"></textarea>
    @Html.TextArea("TextArea2")
    <br>
輸出結果:
<label for="CheckBox:">CheckBox:</label><br>
    <input id="Checkbox1" name="group1" type="checkbox" value="yes" checked="checked"/>yes
    <input id="Checkbox2" name="group1" type="checkbox" value="no" /><input name="group1" type="hidden" value="false" />
    <label for="checkbox1">no</label>
    <br>
    <label for="RadioButton:">RadioButton:</label><br>
    <input id="RadioButton1" name="group2" type="radio" value="man"/>man
    <input checked="checked" id="rd1" name="group2" type="radio" value="female" />female
    <br>
    <label for="Textbox:">Textbox:</label><br>
    First name: <input id="textbox1" name="name" type="text" value=""><br>
    Last name:  <input id="textbox2" name="name" type="text" value="" />
    <br>
    <label for="Password:">Password:</label><br>
    Password: <input id="password1" name="pwd" type="password">
    confim Password:<input id="password2" name="pwd" type="password" value="" />
    <br>
    <label for="Hidden:">Hidden:</label><br>
    <input id="Hidden1" name="hide" type="hidden" value="text" />
    <input id="Hidden2" name="hide" type="hidden" value="text" />
    <br>
    <label for="TextArea:">TextArea:</label><br>
    <textarea cols="20" id="TextArea1" name="TextArea1" rows="2"></textarea>
    <textarea cols="20" id="TextArea2" name="TextArea2" rows="2">
</textarea>
    <br>
而RadioButton的屬性name要一樣才能只選其中之一

3月 19, 2014

純javascript

function aa(){
document.getElementById("ff12").innerHTML = document.getElementById("aa1").value;
document.getElementById("ff9").innerHTML = document.getElementById("aa4").value;
document.getElementById("ff4").innerHTML = document.getElementById("aa9").value;
document.getElementById("ff1").innerHTML = document.getElementById("aa12").value;
document.getElementById("ff11").innerHTML = document.getElementById("aa2").value;
document.getElementById("ff10").innerHTML = document.getElementById("aa3").value;
document.getElementById("ff2").innerHTML = document.getElementById("aa11").value;
document.getElementById("ff3").innerHTML = document.getElementById("aa10").value;
document.getElementById("ff5").innerHTML = document.getElementById("aa8").value;
document.getElementById("ff6").innerHTML = document.getElementById("aa7").value;
document.getElementById("ff7").innerHTML = document.getElementById("aa6").value;
document.getElementById("ff8").innerHTML = document.getElementById("aa5").value;
}

3月 12, 2014

開新視窗

 protected void btn_Click(object sender, EventArgs e)
    {
        string newWin =

        "window.open('pub.aspx');";

        ClientScript.RegisterStartupScript

            (this.GetType(), "pop", newWin, true);
        
    }

3月 08, 2014

MVC

View:
<script>
    $(document).ready(function () {
        
        $("#s1").click(function () {
            var selected = $("#do1 option:selected");
            $.post("@Url.Content("~/store/bgg")",
                    {user:selected.val()},
                    function (res) {
                        alert(res);
                    });
            
        });
        //$("#do1").click
    })
</script>
<h2>indexstore</h2>
<select id="do1">
    <option>dog</option>
    <option>pig</option>
</select>
<input id="s1" type="submit" value="submit" />
controll加入:
public ActionResult bgg(string user)
{
            
    return  Content(string.Format("已傳送訊息給{0}",user));
}