Download link . select tag a by jquery
One: a.txt
a file contains HTML;
<asp:HyperLink ID="downloadLink" ="~/Download/a.txt" runat="server">downloadLink</asp:HyperLink>
When I click on the downloadLink
The file will be downloaded. But this code shows the files content in the browser.
If the tag number a 3 How can we have. When clicking on each one will give it to us href;
<a href="k1">kp1</a>
<a href="k2">kp2</a>
开发者_运维百科<a href="k3">kp3</a>
when click on kp1 alert me k1 and when click on kp2 alert me k2 and...
If I understand the second part of your question correctly (I cannot make sense of the first part), you want something like:
$(document).ready(function() {
$("a").click(function() {
window.alert($(this).attr("href"));
});
});
I'm not entirely sure what you mean but does this do what your looking for?
http://jsfiddle.net/ememV/1/
For your first point, you want to create a proxy .aspx page that loads your text file and serves it back after setting the ContentType
to something like application/octet-stream
:
private void Page_Load(object sender, System.EventArgs e)
{
Response.ContentType = "Application/octet-stream";
string FilePath = MapPath("~/Download/a.txt"); // or you can read
// it from Request.Form
Response.WriteFile(FilePath);
Response.End();
}
Alternatively, set the .txt
content type in IIS to application/octet-stream
.
For the second, something as simple as this would work:
$(function(){
$('a').click(function(){
alert($(this).attr('href');
return false; // to prevent the redirect
});
});
Note however that storing data in href
is a pretty bad idea. Use title
or a custom attribute instead.
精彩评论