在Javascript中弹出窗口内的按钮

时间:2014-03-11 04:35:03

标签: javascript

在Javascript中弹出窗口中有一个按钮需要什么代码? 然后该按钮的功能是转到另一个页面 这是我的代码:

<script type="text/javascript">
    function openWin() {
        var myBtn = document.getElementById("myBtn");

        myBtn = window.open('', '', 'width=200,height=300');
        myBtn.document.write("<p>Lot Name: Esperanza</p>");
        myBtn.document.write("<p>Lot Price: P800,000</p>");
        myBtn.document.write("<p>Lot Size: 50 sq. metres</p>");
        myBtn.focus();


        function gotoreserve() {
            window.location.href = "localhost/tola/reserve.php";
        }


    }
</script>

enter image description here

3 个答案:

答案 0 :(得分:1)

<script type="text/javascript">
    function openWin() {
        var myBtn = document.getElementById("myBtn");

        myBtn = window.open('', '', 'width=200,height=300');
        myBtn.document.write("<p>Lot Name: Esperanza</p>");
        myBtn.document.write("<p>Lot Price: P800,000</p>");
        myBtn.document.write("<p>Lot Size: 50 sq. metres</p>");

        // Add a button element here
        myBtn.document.write('<button onclick="gotoreserve()">Click Me!</button>');

        myBtn.focus();


        function gotoreserve() {
            window.location.href = "localhost/tola/reserve.php";
        }
    }
</script>

答案 1 :(得分:1)

<script type="text/javascript">
function openWin()
{
var myBtn=document.getElementById("myBtn");

 myBtn=window.open('','','width=200,height=300');
 myBtn.document.write("<p>Lot Name: Esperanza</p>");
 myBtn.document.write("<p>Lot Price: P800,000</p>");
 myBtn.document.write("<p>Lot Size: 50 sq. metres</p>");
 myBtn.document.write("<input type='button' value='GoToReserve' onclick='gotoreserve()'>");
 myBtn.focus();


function gotoreserve()
{
window.location.href = "localhost/tola/reserve.php";
}


}
</script>

答案 2 :(得分:1)

尝试这种棘手的DOM方式,

<script type="text/javascript">
function openWin() {
    var myBtn = document.getElementById("myBtn");

    myBtn = window.open('', '', 'width=200,height=300');
    myBtn.document.write("<p>Lot Name: Esperanza</p>");
    myBtn.document.write("<p>Lot Price: P800,000</p>");
    myBtn.document.write("<p>Lot Size: 50 sq. metres</p>");

    // Add a button element here
    var button = document.createElement("input");
    button.type = "button";
    button.value = "im a button";
    button.onclick = "gotoreserve()";
    mybtn.appendChild(button);

    function gotoreserve() {
        window.location.href = "localhost/tola/reserve.php";
    }
}
</script>