<input id="message" type="text" style="width:200px; height:30px; font-size:24px;" />
<input type="button" value="BUTTON"onClick="twitterAPI()" style="height:30px;" />


<div id="twitter" style="margin:20px 0px; display:none"></div>


<script src="jquery-1.6.2.min.js" type="text/javascript"></script>
<script src="jquery.dataset.js" type="text/javascript"></script>
<script>
twitterAPI();
function twitterAPI(){
    
    var data_url = "http://blog.alt-scape.com";
    var data_via = "alt_scape";
    var data_text = $("#message").val();
    var data_related = "alt_scape";
    
    // 要素の存在チェック
    if($("#twitter iframe").size() > 0){
        $("#twitter script").remove();
        $("#twitter iframe").remove();
    }
    
    $(function(){
        var e = document.createElement('script');
        e.src = document.location.protocol + '//platform.twitter.com/widgets.js';
        e.async = true;
        document.getElementById('twitter').appendChild(e);
        
        $("#twitter").append("<a href='http://twitter.com/share' class='twitter-share-button'>Tweet</a>");
        $('#twitter a').dataset({
            url: data_url,
            via: data_via,
            text: data_text,
            related: data_related
        });
        $("#twitter").fadeIn("slow");
    });
}
</script>